#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*/ clearenv();
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ strchr(char *, char);
int /*<<< orphan*/ unsetenv(int /*<<< orphan*/);
int bake_args(int argc, char **argv) {
  int ch;
  while ((ch = getopt(argc, argv, "iu:")) > 0) {
    switch (ch) {
    case 'i':
      if (clearenv())
        return 1;
      break;
    case 'u':
      if (unsetenv(optarg) < 0)
        return 1;
      break;
    default:
      break;
    }
  }
  for (; optind < argc; optind++) {
    if (!strchr(argv[optind], '='))
      break;
    putenv(argv[optind]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<bake_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11f6 <bake_args+0xa6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x69,%eax
je     11a3 <bake_args+0x53>
jmp    1192 <bake_args+0x42>
mov    -0x18(%rbp),%eax
sub    $0x75,%eax
je     11c4 <bake_args+0x74>
jmp    11ec <bake_args+0x9c>
mov    $0x0,%al
call   1030 <clearenv@plt>
cmp    $0x0,%eax
je     11bf <bake_args+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    126f <bake_args+0x11f>
jmp    11f1 <bake_args+0xa1>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <unsetenv@plt>
cmp    $0x0,%eax
jge    11e7 <bake_args+0x97>
movl   $0x1,-0x4(%rbp)
jmp    126f <bake_args+0x11f>
jmp    11f1 <bake_args+0xa1>
jmp    11f1 <bake_args+0xa1>
jmp    115f <bake_args+0xf>
jmp    11fb <bake_args+0xab>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1268 <bake_args+0x118>
mov    -0x10(%rbp),%rax
mov    0x2dc8(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
jne    1237 <bake_args+0xe7>
jmp    1268 <bake_args+0x118>
mov    -0x10(%rbp),%rax
mov    0x2d9e(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <putenv@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d7f(%rip),%rax
mov    %ecx,(%rax)
jmp    11fb <bake_args+0xab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bake_args>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe9d(%rip),%rdx
call   1060 <getopt@plt>
test   %eax,%eax
jle    11c6 <bake_args+0x76>
mov    0x2e85(%rip),%r15
lea    0xe86(%rip),%r14
jmp    119d <bake_args+0x4d>
nopl   0x0(%rax)
mov    (%r15),%edi
call   1070 <unsetenv@plt>
test   %eax,%eax
js     11b2 <bake_args+0x62>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
test   %eax,%eax
jle    11c6 <bake_args+0x76>
cmp    $0x75,%eax
je     1180 <bake_args+0x30>
cmp    $0x69,%eax
jne    118c <bake_args+0x3c>
xor    %eax,%eax
call   1030 <clearenv@plt>
test   %eax,%eax
je     118c <bake_args+0x3c>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e13(%rip),%r15
mov    (%r15),%eax
xor    %r14d,%r14d
cmp    %ebp,%eax
jge    11b8 <bake_args+0x68>
nopw   0x0(%rax,%rax,1)
cltq
mov    (%rbx,%rax,8),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %eax,%eax
je     11b8 <bake_args+0x68>
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rdi
call   1050 <putenv@plt>
mov    (%r15),%eax
add    $0x1,%eax
mov    %eax,(%r15)
cmp    %ebp,%eax
jl     11e0 <bake_args+0x90>
jmp    11b8 <bake_args+0x68>

LLVM IR (-O0):
@.str = [4 x i8] c"iu:\00"
@optarg = global i32 0
@optind = global i32 0
define i32 @bake_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %7
%13 = load i32, i32* %6
switch i32 %13, label %25 [
i32 105, label %14
i32 117, label %19
]
14: ; preds = %12
%15 = call i32 (...) @clearenv()
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %3
br label %52
18: ; preds = %14
br label %26
19: ; preds = %12
%20 = load i32, i32* @optarg
%21 = call i32 @unsetenv(i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %3
br label %52
24: ; preds = %19
br label %26
25: ; preds = %12
br label %26
26: ; preds = %25, %24, %18
br label %7
27: ; preds = %7
br label %28
28: ; preds = %48, %27
%29 = load i32, i32* @optind
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @strchr(i8* %37, i8 signext 61)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %32
br label %51
41: ; preds = %32
%42 = load i8**, i8*** %5
%43 = load i32, i32* @optind
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @putenv(i8* %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* @optind
%50 = add nsw i32 %49, 1
store i32 %50, i32* @optind
br label %28
51: ; preds = %40, %28
store i32 0, i32* %3
br label %52
52: ; preds = %51, %23, %17
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [4 x i8] c"iu:\00"
@optarg = global i32 0
@optind = global i32 0
define i32 @bake_args(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %17, %2
%6 = load i32, i32* @optind
%7 = icmp slt i32 %6, %0
br i1 %7, label %20, label %36
8: ; preds = %2, %17
%9 = phi i32 [ %18, %17 ], [ %3, %2 ]
switch i32 %9, label %17 [
i32 105, label %10
i32 117, label %13
]
10: ; preds = %8
%11 = tail call i32 (...) @clearenv()
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %36
13: ; preds = %8
%14 = load i32, i32* @optarg
%15 = tail call i32 @unsetenv(i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %36, label %17
17: ; preds = %8, %13, %10
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp sgt i32 %18, 0
br i1 %19, label %8, label %5
20: ; preds = %5, %27
%21 = phi i32 [ %34, %27 ], [ %6, %5 ]
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @strchr(i8* %24, i8 signext 61)
%26 = icmp eq i32 %25, 0
br i1 %26, label %36, label %27
27: ; preds = %20
%28 = load i32, i32* @optind
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @putenv(i8* %31)
%33 = load i32, i32* @optind
%34 = add nsw i32 %33, 1
store i32 %34, i32* @optind
%35 = icmp slt i32 %34, %0
br i1 %35, label %20, label %36
36: ; preds = %13, %10, %20, %27, %5
%37 = phi i32 [ 0, %5 ], [ 0, %27 ], [ 0, %20 ], [ 1, %10 ], [ 1, %13 ]
ret i32 %37
}