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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int stat(char *, struct stat *);
void getfistat1(void) {
  int ret;
  int fd;
  struct stat sbuf;
  ret = stat("./a.out", &sbuf);
  if (ret < 0) {
    perror("fstat fail:");
    return;
  }
  printf("ino %ld\n", sbuf.st_ino);
  fd = open("./a.out", O_RDONLY);
  if (fd < 0) {
    perror("open fail:");
    return;
  }
  ret = fstat(fd, &sbuf);
  if (ret < 0) {
    perror("fstat fail:");
    return;
  }
  printf("ino %ld\n", sbuf.st_ino);
}


x86 assembly (clang, -O0):
<getfistat1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1186 <getfistat1+0x36>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
jmp    1201 <getfistat1+0xb1>
mov    -0x10(%rbp),%esi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c8 <getfistat1+0x78>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
jmp    1201 <getfistat1+0xb1>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1070 <fstat@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11f2 <getfistat1+0xa2>
lea    0xe20(%rip),%rdi
call   1060 <perror@plt>
jmp    1201 <getfistat1+0xb1>
mov    -0x10(%rbp),%esi
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfistat1>:
push   %rax
lea    0xea8(%rip),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %eax,%eax
js     11aa <getfistat1+0x5a>
mov    (%rsp),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11b7 <getfistat1+0x67>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
test   %eax,%eax
js     11aa <getfistat1+0x5a>
mov    (%rsp),%esi
lea    0xe70(%rip),%rdi
pop    %rax
jmp    1030 <printf@plt>
lea    0xe57(%rip),%rdi
pop    %rax
jmp    1060 <perror@plt>
lea    0xe5f(%rip),%rdi
pop    %rax
jmp    1060 <perror@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"./a.out\00"
@.str.1 = [12 x i8] c"fstat fail:\00"
@.str.2 = [9 x i8] c"ino %ld\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [11 x i8] c"open fail:\00"
define void @getfistat1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.stat
%4 = call i32 @stat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %30
9: ; preds = %0
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %30
19: ; preds = %9
%20 = load i32, i32* %2
%21 = call i32 @fstat(i32 %20, %struct.stat* %3)
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %30
26: ; preds = %19
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %24, %17, %7
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"./a.out\00"
@.str.1 = [12 x i8] c"fstat fail:\00"
@.str.2 = [9 x i8] c"ino %ld\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [11 x i8] c"open fail:\00"
define void @getfistat1() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %24
7: ; preds = %0
%8 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %24
16: ; preds = %7
%17 = call i32 @fstat(i32 %12, %struct.stat* %1)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %24
21: ; preds = %16
%22 = load i32, i32* %8
%23 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %19, %14, %5
ret void
}