#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_mode;
  int st_size;
  int st_uid;
  int st_gid;
};

/* Variables and functions */
int /*<<< orphan*/ ac_syscall_geterrno();
int ac_syscall_stat_mode(char const *);
int /*<<< orphan*/ errno;
int stat(const char *path, struct stat *buf) {
  int mode = ac_syscall_stat_mode(path);
  if (!mode) {
    errno = ac_syscall_geterrno();
    return -1;
  } else {
    buf->st_mode = mode;
    buf->st_size = 1;
    buf->st_uid = 1;
    buf->st_gid = 1;
    return 0;
  }
}


x86 assembly (clang, -O0):
<stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ac_syscall_stat_mode@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1164 <stat+0x44>
mov    $0x0,%al
call   1030 <ac_syscall_geterrno@plt>
mov    %eax,%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <stat+0x75>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0xc(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat>:
push   %rbx
mov    %rsi,%rbx
call   1040 <ac_syscall_stat_mode@plt>
test   %eax,%eax
je     1148 <stat+0x28>
mov    %eax,(%rbx)
movabs $0x100000001,%rax
mov    %rax,0x4(%rbx)
movl   $0x1,0xc(%rbx)
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1030 <ac_syscall_geterrno@plt>
mov    0x2e8a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32 }
@errno = global i32 0
define i32 @stat(i8* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
%7 = load i8*, i8** %4
%8 = call i32 @ac_syscall_stat_mode(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 (...) @ac_syscall_geterrno()
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %23
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load %struct.stat*, %struct.stat** %5
%16 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load %struct.stat*, %struct.stat** %5
%18 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 1
store i32 1, i32* %18
%19 = load %struct.stat*, %struct.stat** %5
%20 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 2
store i32 1, i32* %20
%21 = load %struct.stat*, %struct.stat** %5
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 3
store i32 1, i32* %22
store i32 0, i32* %3
br label %23
23: ; preds = %13, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32 }
@errno = global i32 0
define i32 @stat(i8* %0, %struct.stat* nocapture writeonly %1) {
%3 = tail call i32 @ac_syscall_stat_mode(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @ac_syscall_geterrno()
store i32 %6, i32* @errno
br label %12
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 %3, i32* %8
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
store i32 1, i32* %9
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 3
store i32 1, i32* %11
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ 0, %7 ], [ -1, %5 ]
ret i32 %13
}