#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ handleArchive(char *);
int /*<<< orphan*/ handleObjectFile(char *);
scalar_t__ isArchive(char *);
scalar_t__ isObjectFile(char *);
int /*<<< orphan*/ printDefinedList();
int /*<<< orphan*/ printUndefinedErrors();
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  int i, istat;
  struct stat stFileInfo;
  if (argc <= 1) {
    printf("resolve: no input files\n");
    exit(1);
  }
  for (i = 1; i < argc; i++) {
    istat = stat(argv[i], &stFileInfo);
    if (istat == 0) {
      if (!isObjectFile(argv[i]) && !isArchive(argv[i])) {
        printf("%s: file not recognized\n", argv[i]);
      } else {
        if (isArchive(argv[i]))
          handleArchive(argv[i]);
        if (isObjectFile(argv[i]))
          handleObjectFile(argv[i]);
      }
    } else {
      printf("%s: file not found\n", argv[i]);
    }
  }
  printUndefinedErrors();
  printDefinedList();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11c8 <main+0x38>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e1 <main+0x151>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12b4 <main+0x124>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <isObjectFile@plt>
cmp    $0x0,%rax
jne    1252 <main+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <isArchive@plt>
cmp    $0x0,%rax
jne    1252 <main+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12af <main+0x11f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <isArchive@plt>
cmp    $0x0,%rax
je     127e <main+0xee>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <handleArchive@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <isObjectFile@plt>
cmp    $0x0,%rax
je     12aa <main+0x11a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <handleObjectFile@plt>
jmp    12af <main+0x11f>
jmp    12ce <main+0x13e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d3 <main+0x143>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <main+0x3f>
mov    $0x0,%al
call   1090 <printUndefinedErrors@plt>
mov    $0x0,%al
call   1080 <printDefinedList@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     127a <main+0xda>
mov    %rsi,%rbx
mov    %edi,%r13d
mov    $0x1,%ebp
mov    %rsp,%r14
lea    0xe37(%rip),%r15
lea    0xe49(%rip),%r12
jmp    11f3 <main+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     125b <main+0xbb>
mov    (%rbx,%rbp,8),%rdi
mov    %r14,%rsi
call   1060 <stat@plt>
mov    (%rbx,%rbp,8),%rsi
test   %eax,%eax
jne    11e0 <main+0x40>
mov    %rsi,%rdi
call   1070 <isObjectFile@plt>
test   %rax,%rax
jne    1222 <main+0x82>
mov    (%rbx,%rbp,8),%rdi
call   1040 <isArchive@plt>
test   %rax,%rax
je     1252 <main+0xb2>
mov    (%rbx,%rbp,8),%rdi
call   1040 <isArchive@plt>
test   %rax,%rax
je     1239 <main+0x99>
mov    (%rbx,%rbp,8),%rdi
call   10c0 <handleArchive@plt>
mov    (%rbx,%rbp,8),%rdi
call   1070 <isObjectFile@plt>
test   %rax,%rax
je     11ea <main+0x4a>
mov    (%rbx,%rbp,8),%rdi
call   1080 <handleObjectFile@plt>
jmp    11ea <main+0x4a>
mov    (%rbx,%rbp,8),%rsi
mov    %r15,%rdi
jmp    11e3 <main+0x43>
xor    %eax,%eax
call   10a0 <printUndefinedErrors@plt>
xor    %eax,%eax
call   1090 <printDefinedList@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [25 x i8] c"resolve: no input files\0A\00"
@.str.1 = [25 x i8] c"%s: file not recognized\0A\00"
@.str.2 = [20 x i8] c"%s: file not found\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 %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
store i32 1, i32* %6
br label %15
15: ; preds = %91, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %94
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @stat(i8* %24, %struct.stat* %8)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %83
28: ; preds = %19
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @isObjectFile(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %51, label %36
36: ; preds = %28
%37 = load i8**, i8*** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i64 @isArchive(i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %82
51: ; preds = %36, %28
%52 = load i8**, i8*** %5
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i64 @isArchive(i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %51
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 @handleArchive(i8* %64)
br label %66
66: ; preds = %59, %51
%67 = load i8**, i8*** %5
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i64 @isObjectFile(i8* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %66
%75 = load i8**, i8*** %5
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @handleObjectFile(i8* %79)
br label %81
81: ; preds = %74, %66
br label %82
82: ; preds = %81, %44
br label %90
83: ; preds = %19
%84 = load i8**, i8*** %5
%85 = load i32, i32* %6
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %84, i64 %86
%88 = load i8*, i8** %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %83, %82
br label %91
91: ; preds = %90
%92 = load i32, i32* %6
%93 = add nsw i32 %92, 1
store i32 %93, i32* %6
br label %15
94: ; preds = %15
%95 = call i32 (...) @printUndefinedErrors()
%96 = call i32 (...) @printDefinedList()
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [25 x i8] c"%s: file not recognized\0A\00"
@.str.2 = [20 x i8] c"%s: file not found\0A\00"
@str = [24 x i8] c"resolve: no input files\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %6, %44
%12 = phi i64 [ 1, %6 ], [ %45, %44 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @stat(i8* %14, %struct.stat* %3)
%16 = icmp eq i32 %15, 0
%17 = load i8*, i8** %13
br i1 %16, label %18, label %42
18: ; preds = %11
%19 = tail call i64 @isObjectFile(i8* %17)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i8*, i8** %13
%23 = tail call i64 @isArchive(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %13
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %44
28: ; preds = %21, %18
%29 = load i8*, i8** %13
%30 = tail call i64 @isArchive(i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i8*, i8** %13
%34 = tail call i32 @handleArchive(i8* %33)
br label %35
35: ; preds = %32, %28
%36 = load i8*, i8** %13
%37 = tail call i64 @isObjectFile(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = load i8*, i8** %13
%41 = tail call i32 @handleObjectFile(i8* %40)
br label %44
42: ; preds = %11
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %44
44: ; preds = %42, %35, %39, %25
%45 = add nuw nsw i64 %12, 1
%46 = icmp eq i64 %45, %7
br i1 %46, label %47, label %11
47: ; preds = %44
%48 = tail call i32 (...) @printUndefinedErrors()
%49 = tail call i32 (...) @printDefinedList()
ret i32 0
}