#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 st_size;
};

/* Variables and functions */
scalar_t__ EFAULT;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
int main(int argc, char **argv) {
  struct stat st;
  if (2 != argc) {
    printf("Usage: sel_ldr test_stat.nexe test_stat_data\n");
    return 1;
  }
  st.st_size = 0;
  assert(-1 == stat(NULL, &st));
  assert(EFAULT == errno);
  assert(-1 == stat(".", NULL));
  assert(EFAULT == errno);
  errno = 0;
  assert(0 == stat(argv[1], &st));
  assert(0 == errno);
  assert(30 == st.st_size);
  return 0;
}


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)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     116c <main+0x3c>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1265 <main+0x135>
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dd3(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1e,%eax
cmp    -0x18(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1204 <main+0xd4>
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
xor    %r14d,%r14d
lea    0x8(%rsp),%r15
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e80(%rip),%r13
mov    0x0(%r13),%rax
mov    0x2e55(%rip),%r12
xor    %edi,%edi
cmp    (%r12),%rax
sete   %dil
call   1040 <assert@plt>
lea    0xe67(%rip),%rdi
xor    %esi,%esi
call   1050 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%rax
xor    %edi,%edi
cmp    (%r12),%rax
sete   %dil
call   1040 <assert@plt>
movq   $0x0,(%r12)
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1050 <stat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%r12)
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0x1e,0x8(%rsp)
sete   %dil
call   1040 <assert@plt>
jmp    1216 <main+0xe6>
lea    0xdf7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [46 x i8] c"Usage: sel_ldr test_stat.nexe test_stat_data\0A\00"
@EFAULT = global i64 0
@errno = global i64 0
@.str.1 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 2, %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
store i32 0, i32* %12
%13 = call i32 @stat(i8* null, %struct.stat* %6)
%14 = icmp eq i32 -1, %13
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64, i64* @EFAULT
%18 = load i64, i64* @errno
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.stat* null)
%23 = icmp eq i32 -1, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i64, i64* @EFAULT
%27 = load i64, i64* @errno
%28 = icmp eq i64 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
store i64 0, i64* @errno
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @stat(i8* %33, %struct.stat* %6)
%35 = icmp eq i32 0, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i64, i64* @errno
%39 = icmp eq i64 0, %38
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%43 = load i32, i32* %42
%44 = icmp eq i32 30, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
store i32 0, i32* %3
br label %47
47: ; preds = %11, %9
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EFAULT = global i64 0
@errno = global i64 0
@.str.1 = [2 x i8] c".\00"
@str = [45 x i8] c"Usage: sel_ldr test_stat.nexe test_stat_data\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %42
8: ; preds = %2
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
store i32 0, i32* %9
%10 = call i32 @stat(i8* null, %struct.stat* %3)
%11 = icmp eq i32 %10, -1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i64, i64* @EFAULT
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.stat* null)
%20 = icmp eq i32 %19, -1
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = load i64, i64* @EFAULT
%24 = load i64, i64* @errno
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
store i64 0, i64* @errno
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @stat(i8* %29, %struct.stat* %3)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = load i64, i64* @errno
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, 30
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
br label %42
42: ; preds = %8, %6
%43 = phi i32 [ 1, %6 ], [ 0, %8 ]
ret i32 %43
}