#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_blocks;
  int /*<<< orphan*/ st_blksize;
  int /*<<< orphan*/ st_size;
  int /*<<< orphan*/ st_ino;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int stat(char const *, struct stat *);
int stat_file(const char *filename) {
  int ret;
  struct stat st;
  ret = stat(filename, &st);
  if (ret < 0) {
    perror("fstat");
    return 1;
  }
  printf("ino    : %lu\n", st.st_ino);
  printf("size   : %ld\n", st.st_size);
  printf("blksize: %ld\n", st.st_blksize);
  printf("blocks : %ld\n", st.st_blocks);
  return 0;
}


x86 assembly (clang, -O0):
<stat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    116e <stat_file+0x3e>
lea    0xea3(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <stat_file+0x81>
mov    -0x1c(%rbp),%esi
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_file>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
js     1189 <stat_file+0x59>
mov    0x14(%rsp),%esi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x18,%rsp
ret

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

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