#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 */
scalar_t__ bake_args(int, char **);
scalar_t__ execvp(char *, char **);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printenv();
int main(int argc, char **argv) {
  if (bake_args(argc, argv)) {
    perror("env");
    return 1;
  }
  if (argc <= optind) {
    printenv();
    return 0;
  }
  if (execvp(argv[optind], &argv[optind]) < 0) {
    perror("env");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <bake_args@plt>
cmp    $0x0,%rax
je     1184 <main+0x44>
lea    0xe8d(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xbe>
mov    -0x8(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
jg     11a9 <main+0x69>
mov    $0x0,%al
call   1030 <printenv@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fe <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x2e34(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e22(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1050 <execvp@plt>
cmp    $0x0,%rax
jge    11f7 <main+0xb7>
lea    0xe1a(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1060 <bake_args@plt>
test   %rax,%rax
jne    1174 <main+0x34>
mov    0x2e8f(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1187 <main+0x47>
lea    (%rbx,%rax,8),%rsi
mov    (%rbx,%rax,8),%rdi
call   1050 <execvp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    1190 <main+0x50>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%ebx
jmp    1190 <main+0x50>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printenv@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"env\00"
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = load i8**, i8*** %5
%8 = call i64 @bake_args(i32 %6, i8** %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
12: ; preds = %2
%13 = load i32, i32* %4
%14 = load i32, i32* @optind
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (...) @printenv()
store i32 0, i32* %3
br label %33
18: ; preds = %12
%19 = load i8**, i8*** %5
%20 = load i32, i32* @optind
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = load i32, i32* @optind
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = call i64 @execvp(i8* %23, i8** %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
32: ; preds = %18
store i32 0, i32* %3
br label %33
33: ; preds = %32, %30, %16, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"env\00"
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @bake_args(i32 %0, i8** %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = load i32, i32* @optind
%9 = icmp slt i32 %8, %0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (...) @printenv()
br label %20
12: ; preds = %7
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i64 @execvp(i8* %15, i8** %14)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %12, %18, %10, %5
%21 = phi i32 [ 1, %5 ], [ 0, %10 ], [ 1, %18 ], [ 0, %12 ]
ret i32 %21
}