#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;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EFAULT;
scalar_t__ ENOENT;
int S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int stat(char *, struct stat *);
int test_stat(void) {
  struct stat sb;
  assert(stat("/tests/ascii", &sb) == 0);
  assert(sb.st_size == 95);
  assert(S_ISREG(sb.st_mode));
  assert(stat("/tests/ascii", NULL) == -1 && errno == EFAULT);
  assert(stat("/dont/exist", &sb) == -1 && errno == ENOENT);
  return 0;
}


x86 assembly (clang, -O0):
<test_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x5f,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%edi
call   1050 <S_ISREG@plt>
mov    %eax,%edi
call   1030 <assert@plt>
lea    0xe81(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x9(%rbp)
jne    11b2 <test_stat+0x82>
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    0xe47(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0xa(%rbp)
jne    11f9 <test_stat+0xc9>
mov    0x2df2(%rip),%rax
mov    (%rax),%rax
mov    0x2dd8(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_stat>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <stat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x5f,(%rsp)
sete   %dil
call   1030 <assert@plt>
mov    0x4(%rsp),%edi
call   1050 <S_ISREG@plt>
mov    %eax,%edi
call   1030 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2e4c(%rip),%rbx
mov    (%rbx),%rcx
mov    0x2e62(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%rbx),%rcx
mov    0x2e03(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [13 x i8] c"/tests/ascii\00"
@errno = global i64 0
@EFAULT = global i64 0
@.str.1 = [12 x i8] c"/dont/exist\00"
@ENOENT = global i64 0
define i32 @test_stat() {
%1 = alloca %struct.stat
%2 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 95
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @S_ISREG(i32 %12)
%14 = call i32 @assert(i32 %13)
%15 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* null)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = load i64, i64* @errno
%19 = load i64, i64* @EFAULT
%20 = icmp eq i64 %18, %19
br label %21
21: ; preds = %17, %0
%22 = phi i1 [ false, %0 ], [ %20, %17 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br label %31
31: ; preds = %27, %21
%32 = phi i1 [ false, %21 ], [ %30, %27 ]
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [13 x i8] c"/tests/ascii\00"
@errno = global i64 0
@EFAULT = global i64 0
@.str.1 = [12 x i8] c"/dont/exist\00"
@ENOENT = global i64 0
define i32 @test_stat() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 95
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%13 = load i32, i32* %12
%14 = tail call i32 @S_ISREG(i32 %13)
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* null)
%17 = icmp eq i32 %16, -1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EFAULT
%20 = icmp eq i64 %18, %19
%21 = select i1 %17, i1 %20, i1 false
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = call i32 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%25 = icmp eq i32 %24, -1
%26 = load i64, i64* @errno
%27 = load i64, i64* @ENOENT
%28 = icmp eq i64 %26, %27
%29 = select i1 %25, i1 %28, i1 false
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
ret i32 0
}