#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*/ PATH_MAX;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
char *realpath(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
int main(int argc, char **argv) {
  int i, nullAs2ndArg =
             (strncasecmp(argv[0] + strlen(argv[0]) - 6, "nonull", 6) != 0);
  for (i = 1; i < argc; ++i) {
    char buf[PATH_MAX + 1];
    char *resolved_path = realpath(argv[i], nullAs2ndArg ? NULL : buf);
    if (resolved_path) {
      printf("%s\n-> %s\n", argv[i], resolved_path);
      if (nullAs2ndArg)
        free(resolved_path);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffa,%rdi
lea    0xe6f(%rip),%rsi
mov    $0x6,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1283 <main+0x133>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1211 <main+0xc1>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    121e <main+0xce>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    121e <main+0xce>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1060 <realpath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     126e <main+0x11e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdb6(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     1269 <main+0x119>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    126e <main+0x11e>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b1 <main+0x61>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    (%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffa,%rdi
lea    0xe80(%rip),%rsi
mov    $0x6,%edx
call   1070 <strncasecmp@plt>
cmp    $0x2,%r15d
jl     121c <main+0xcc>
mov    %rax,%r12
mov    %r15d,%eax
mov    %rax,-0x30(%rbp)
mov    $0x1,%r15d
jmp    11bd <main+0x6d>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rsp
add    $0x1,%r15
cmp    %r15,-0x30(%rbp)
je     121c <main+0xcc>
mov    %rsp,%r13
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rsi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
test   %r12,%r12
mov    (%r14,%r15,8),%rdi
mov    $0x0,%eax
cmovne %rax,%rsi
call   1060 <realpath@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    %rax,%rbx
mov    (%r14,%r15,8),%rsi
lea    0xe02(%rip),%rdi
mov    %rax,%rdx
call   1050 <printf@plt>
test   %r12,%r12
je     11b0 <main+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11b0 <main+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"nonull\00"
@PATH_MAX = global i32 0
@.str.1 = [10 x i8] c"%s\0A-> %s\0A\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 i8*
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -6
%21 = call i64 @strncasecmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
store i32 %23, i32* %7
store i32 1, i32* %6
br label %24
24: ; preds = %64, %2
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %67
28: ; preds = %24
%29 = load i32, i32* @PATH_MAX
%30 = add nsw i32 %29, 1
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %8
%33 = alloca i8, i64 %31
store i64 %31, i64* %9
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %28
br label %43
42: ; preds = %28
br label %43
43: ; preds = %42, %41
%44 = phi i8* [ null, %41 ], [ %33, %42 ]
%45 = call i8* @realpath(i8* %38, i8* %44)
store i8* %45, i8** %10
%46 = load i8*, i8** %10
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %62
48: ; preds = %43
%49 = load i8**, i8*** %5
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = load i8*, i8** %10
%55 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %54)
%56 = load i32, i32* %7
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i8*, i8** %10
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %58, %48
br label %62
62: ; preds = %61, %43
%63 = load i8*, i8** %8
br label %64
64: ; preds = %62
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %24
67: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"nonull\00"
@PATH_MAX = global i32 0
@.str.1 = [10 x i8] c"%s\0A-> %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strlen(i8* %3)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %3, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -6
%8 = tail call i64 @strncasecmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%9 = icmp eq i64 %8, 0
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %33
11: ; preds = %2
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %30
%14 = phi i64 [ 1, %11 ], [ %31, %30 ]
%15 = load i32, i32* @PATH_MAX
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = getelementptr inbounds i8*, i8** %1, i64 %14
%21 = load i8*, i8** %20
%22 = select i1 %9, i8* %19, i8* null
%23 = call i8* @realpath(i8* %21, i8* %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %13
%26 = load i8*, i8** %20
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %23)
br i1 %9, label %30, label %28
28: ; preds = %25
%29 = call i32 @free(i8* %23)
br label %30
30: ; preds = %25, %28, %13
%31 = add nuw nsw i64 %14, 1
%32 = icmp eq i64 %31, %12
br i1 %32, label %33, label %13
33: ; preds = %30, %2
ret i32 0
}