#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 statvfs {
  int /*<<< orphan*/ f_blocks;
  int /*<<< orphan*/ f_bsize;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int fstatvfs(int, struct statvfs *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/);
void getfstat2(void) {
  int ret;
  struct statvfs sbuf;
  int fd;
  fd = open("./a.out", O_RDONLY);
  if (fd < 0) {
    perror("open fail:");
    return;
  }
  ret = fstatvfs(fd, &sbuf);
  if (ret < 0) {
    perror("get fail:");
    return;
  }
  printf("fs size %ld blocks %ld \n", sbuf.f_bsize, sbuf.f_blocks);
  close(fd);
}


x86 assembly (clang, -O0):
<getfstat2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118b <getfstat2+0x3b>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
jmp    11cf <getfstat2+0x7f>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <fstatvfs@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11b5 <getfstat2+0x65>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
jmp    11cf <getfstat2+0x7f>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfstat2>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a0 <getfstat2+0x50>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <fstatvfs@plt>
test   %eax,%eax
js     11a9 <getfstat2+0x59>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <close@plt>
lea    0xe61(%rip),%rdi
jmp    11b0 <getfstat2+0x60>
lea    0xe63(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1070 <perror@plt>

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

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