#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 _ldd(char *, char const *);
int _usage();
char *getenv(char *);
int getopt(int, char **, char *);
int optind;
int main(int argc, char *argv[]) {
  int ret = 0;
  int o;
  int i;
  char const *ldpath;
  while ((o = getopt(argc, argv, "")) != -1)
    switch (o) {
    default:
      return _usage();
    }
  if (optind == argc)
    return _usage();
  ldpath = getenv("LD_LIBRARY_PATH");
  for (i = optind; i < argc; i++)
    ret |= _ldd(argv[i], ldpath);
  return (ret == 0) ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     118b <main+0x4b>
mov    $0x0,%al
call   1040 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1210 <main+0xd0>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    11ac <main+0x6c>
mov    $0x0,%al
call   1040 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1210 <main+0xd0>
lea    0xe4d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fd <main+0xbd>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <_ldd@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c8 <main+0x88>
mov    -0x14(%rbp),%edx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r12d
lea    0xeba(%rip),%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
jne    116e <main+0x2e>
mov    0x2e82(%rip),%rax
movslq (%rax),%rbx
cmp    %r12d,%ebx
jne    117d <main+0x3d>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_usage@plt>
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
xor    %eax,%eax
cmp    %r12d,%ebx
jge    11c0 <main+0x80>
lea    (%r15,%rbx,8),%r15
sub    %ebx,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1050 <_ldd@plt>
or     %eax,%ebp
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    11a0 <main+0x60>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
@.str.1 = [16 x i8] c"LD_LIBRARY_PATH\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @_usage()
br label %30
7: ; preds = %2
%8 = load i32, i32* @optind
%9 = icmp eq i32 %8, %0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (...) @_usage()
br label %30
12: ; preds = %7
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp slt i32 %8, %0
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = sext i32 %8 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ %16, %15 ], [ %24, %17 ]
%19 = phi i32 [ 0, %15 ], [ %23, %17 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 %18
%21 = load i8*, i8** %20
%22 = tail call i32 @_ldd(i8* %21, i8* %13)
%23 = or i32 %22, %19
%24 = add nsw i64 %18, 1
%25 = trunc i64 %24 to i32
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %17
27: ; preds = %17
%28 = icmp eq i32 %23, 0
%29 = select i1 %28, i32 0, i32 2
br label %30
30: ; preds = %12, %27, %10, %5
%31 = phi i32 [ %6, %5 ], [ %11, %10 ], [ 0, %12 ], [ %29, %27 ]
ret i32 %31
}