#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int biSet(char *name, char **args, char **environ) {
  int argc = 0;
  static char *res_s[1024] = {0};
  for (argc = 0; args[argc]; argc++) {
  }
  if (3 == argc) {
    sprintf((char *)res_s, "%s=%s", args[1], args[2]);
    putenv((char *)res_s);
    return 0;
  } else if (2 == argc) {
    sprintf((char *)res_s, "%s=", args[1]);
    putenv((char *)res_s);
    return 0;
  } else if (1 == argc) {
    char **curenv = environ;
    while (*curenv) {
      printf("%s\n", *curenv);
      curenv++;
    }
  } else if (3 < argc) {
    printf("To more arguments\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<biSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1178 <biSet+0x48>
jmp    116a <biSet+0x3a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1152 <biSet+0x22>
mov    $0x3,%eax
cmp    -0x24(%rbp),%eax
jne    11c3 <biSet+0x93>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0x2eb3(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    0x2e9e(%rip),%rdi
call   1040 <putenv@plt>
movl   $0x0,-0x4(%rbp)
jmp    1293 <biSet+0x163>
mov    $0x2,%eax
cmp    -0x24(%rbp),%eax
jne    1206 <biSet+0xd6>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0x2e70(%rip),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    0x2e5b(%rip),%rdi
call   1040 <putenv@plt>
movl   $0x0,-0x4(%rbp)
jmp    1293 <biSet+0x163>
mov    $0x1,%eax
cmp    -0x24(%rbp),%eax
jne    1255 <biSet+0x125>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     1250 <biSet+0x120>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    121c <biSet+0xec>
jmp    1282 <biSet+0x152>
mov    $0x3,%eax
cmp    -0x24(%rbp),%eax
jge    127d <biSet+0x14d>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <biSet+0x163>
jmp    1282 <biSet+0x152>
jmp    1287 <biSet+0x157>
jmp    128c <biSet+0x15c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<biSet>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    $0xffffffff,%eax
mov    %rsi,%rcx
xchg   %ax,%ax
add    $0x1,%eax
cmpq   $0x0,(%rcx)
lea    0x8(%rcx),%rcx
jne    1140 <biSet+0x10>
cmp    $0x3,%eax
je     1183 <biSet+0x53>
cmp    $0x2,%eax
je     11a7 <biSet+0x77>
cmp    $0x1,%eax
jne    11cf <biSet+0x9f>
mov    (%rbx),%rdi
xor    %ebp,%ebp
test   %rdi,%rdi
je     11e7 <biSet+0xb7>
add    $0x8,%rbx
xchg   %ax,%ax
call   1030 <puts@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1170 <biSet+0x40>
jmp    11e7 <biSet+0xb7>
mov    0x8(%rsi),%rdx
mov    0x10(%rsi),%rcx
lea    0x2ebe(%rip),%rbx
lea    0xe67(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11c5 <biSet+0x95>
mov    0x8(%rsi),%rdx
lea    0x2e9e(%rip),%rbx
lea    0xe4d(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <putenv@plt>
jmp    11e7 <biSet+0xb7>
xor    %ebp,%ebp
cmp    $0x4,%eax
jb     11e7 <biSet+0xb7>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@biSet.res_s = internal global [1024 x i8*] zeroinitializer
@.str = [6 x i8] c"%s=%s\00"
@.str.1 = [4 x i8] c"%s=\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [19 x i8] c"To more arguments\0A\00"
define i32 @biSet(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8**
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
store i32 0, i32* %8
br label %10
10: ; preds = %18, %3
%11 = load i8**, i8*** %6
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %10
br label %18
18: ; preds = %17
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
br label %10
21: ; preds = %10
%22 = load i32, i32* %8
%23 = icmp eq i32 3, %22
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %6
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %30)
%32 = call i32 @putenv(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*))
store i32 0, i32* %4
br label %67
33: ; preds = %21
%34 = load i32, i32* %8
%35 = icmp eq i32 2, %34
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8**, i8*** %6
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = call i32 @putenv(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*))
store i32 0, i32* %4
br label %67
42: ; preds = %33
%43 = load i32, i32* %8
%44 = icmp eq i32 1, %43
br i1 %44, label %45, label %58
45: ; preds = %42
%46 = load i8**, i8*** %7
store i8** %46, i8*** %9
br label %47
47: ; preds = %51, %45
%48 = load i8**, i8*** %9
%49 = load i8*, i8** %48
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = load i8**, i8*** %9
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i8**, i8*** %9
%56 = getelementptr inbounds i8*, i8** %55, i32 1
store i8** %56, i8*** %9
br label %47
57: ; preds = %47
br label %64
58: ; preds = %42
%59 = load i32, i32* %8
%60 = icmp slt i32 3, %59
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %67
63: ; preds = %58
br label %64
64: ; preds = %63, %57
br label %65
65: ; preds = %64
br label %66
66: ; preds = %65
store i32 0, i32* %4
br label %67
67: ; preds = %66, %61, %36, %24
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@biSet.res_s = internal global [1024 x i8*] zeroinitializer
@.str = [6 x i8] c"%s=%s\00"
@.str.1 = [4 x i8] c"%s=\00"
@str = [18 x i8] c"To more arguments\00"
define i32 @biSet(i8* nocapture readnone %0, i8** nocapture %1, i8** nocapture %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ %9, %4 ], [ 0, %3 ]
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %5 to i32
switch i32 %11, label %34 [
i32 3, label %15
i32 2, label %22
i32 1, label %12
]
12: ; preds = %10
%13 = load i8*, i8** %2
%14 = icmp eq i8* %13, null
br i1 %14, label %38, label %27
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) bitcast ([1024 x i8*]* @biSet.res_s to i8*), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %19)
%21 = tail call i32 @putenv(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*))
br label %38
22: ; preds = %10
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) bitcast ([1024 x i8*]* @biSet.res_s to i8*), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = tail call i32 @putenv(i8* bitcast ([1024 x i8*]* @biSet.res_s to i8*))
br label %38
27: ; preds = %12, %27
%28 = phi i8* [ %32, %27 ], [ %13, %12 ]
%29 = phi i8** [ %31, %27 ], [ %2, %12 ]
%30 = tail call i32 @puts(i8* %28)
%31 = getelementptr inbounds i8*, i8** %29, i64 1
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %38, label %27
34: ; preds = %10
%35 = icmp ugt i32 %11, 3
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %27, %12, %34, %36, %22, %15
%39 = phi i32 [ 0, %15 ], [ 0, %22 ], [ 1, %36 ], [ 0, %34 ], [ 0, %12 ], [ 0, %27 ]
ret i32 %39
}