#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_struct_stat(char *, struct stat *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd, ret;
  char *file;
  struct stat s;
  if (argc < 2) {
    fprintf(stderr, "Usage: stat FILE\n");
    exit(1);
  }
  file = argv[1];
  memset(&s, 0, sizeof(struct stat));
  ret = stat(file, &s);
  if (ret < 0) {
    perror("stat");
    exit(1);
  }
  print_struct_stat("\nTesting stat:", &s);
  memset(&s, 0, sizeof(struct stat));
  ret = lstat(file, &s);
  if (ret < 0) {
    perror("lstat");
    exit(1);
  }
  print_struct_stat("\nTesting lstat:", &s);
  fd = open(file, O_RDONLY);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  memset(&s, 0, sizeof(struct stat));
  ret = fstat(fd, &s);
  if (ret < 0) {
    perror("fstat");
    exit(1);
  }
  print_struct_stat("\nTesting fstat:", &s);
  exit(0);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11cf <main+0x3f>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    121b <main+0x8b>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdf0(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <print_struct_stat@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    126b <main+0xdb>
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdb5(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <print_struct_stat@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12b0 <main+0x120>
lea    0xd96(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10b0 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12ef <main+0x15f>
lea    0xd5c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd4c(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <print_struct_stat@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11b8 <main+0x28>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%rsi),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <stat@plt>
test   %eax,%eax
jns    11e9 <main+0x59>
lea    0xe59(%rip),%rdi
jmp    1278 <main+0xe8>
lea    0xe22(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <print_struct_stat@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <lstat@plt>
test   %eax,%eax
jns    1222 <main+0x92>
lea    0xe01(%rip),%rdi
jmp    1278 <main+0xe8>
lea    0xdfe(%rip),%rdi
mov    %rsp,%rsi
call   1090 <print_struct_stat@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    124f <main+0xbf>
lea    0xdea(%rip),%rdi
jmp    1278 <main+0xe8>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10b0 <fstat@plt>
test   %eax,%eax
jns    1287 <main+0xf7>
lea    0xdc4(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdb4(%rip),%rdi
mov    %rsp,%rsi
call   1090 <print_struct_stat@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: stat FILE\0A\00"
@.str.1 = [5 x i8] c"stat\00"
@.str.2 = [15 x i8] c"\0ATesting stat:\00"
@.str.3 = [6 x i8] c"lstat\00"
@.str.4 = [16 x i8] c"\0ATesting lstat:\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [6 x i8] c"fstat\00"
@.str.7 = [16 x i8] c"\0ATesting fstat:\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 %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = call i32 @memset(%struct.stat* %9, i32 0, i32 4)
%21 = load i8*, i8** %8
%22 = call i32 @stat(i8* %21, %struct.stat* %9)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = call i32 @print_struct_stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %9)
%30 = call i32 @memset(%struct.stat* %9, i32 0, i32 4)
%31 = load i8*, i8** %8
%32 = call i32 @lstat(i8* %31, %struct.stat* %9)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = call i32 @print_struct_stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %9)
%40 = load i8*, i8** %8
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %40, i32 %41)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = call i32 @memset(%struct.stat* %9, i32 0, i32 4)
%50 = load i32, i32* %6
%51 = call i32 @fstat(i32 %50, %struct.stat* %9)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = call i32 @print_struct_stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %9)
%59 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: stat FILE\0A\00"
@.str.1 = [5 x i8] c"stat\00"
@.str.2 = [15 x i8] c"\0ATesting stat:\00"
@.str.3 = [6 x i8] c"lstat\00"
@.str.4 = [16 x i8] c"\0ATesting lstat:\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [6 x i8] c"fstat\00"
@.str.7 = [16 x i8] c"\0ATesting fstat:\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 %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%14 = call i32 @stat(i8* %12, %struct.stat* %3)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = call i32 @print_struct_stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %3)
%21 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%22 = call i32 @lstat(i8* %12, %struct.stat* %3)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = call i32 @print_struct_stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %3)
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %12, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%37 = call i32 @fstat(i32 %30, %struct.stat* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
%43 = call i32 @print_struct_stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %3)
%44 = call i32 @exit(i32 0)
unreachable
}