#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_dev;
  int /*<<< orphan*/ st_blocks;
  int /*<<< orphan*/ st_blksize;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ stat(char const *, struct stat *);
char *strerror(int /*<<< orphan*/);
int main(void) {
  const char const *path = "/";
  struct stat filestat;
  memset(&filestat, 0, sizeof(struct stat));
  if (stat(path, &filestat) >= 0) {
    printf("blksize: %ld, allocated 512B num: %ld, dev: %ld",
           filestat.st_blksize, filestat.st_blocks, filestat.st_dev);
  } else {
    printf("get stat of file error!error reason: %s", strerror(errno));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jl     119e <main+0x5e>
movslq -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bd <main+0x7d>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     1187 <main+0x47>
movslq 0x8(%rsp),%rsi
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a6 <main+0x66>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe96(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [48 x i8] c"blksize: %ld, allocated 512B num: %ld, dev: %ld\00"
@.str.2 = [40 x i8] c"get stat of file error!error reason: %s\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.stat
store i32 0, i32* %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = call i32 @memset(%struct.stat* %3, i32 0, i32 12)
%5 = load i8*, i8** %2
%6 = call i64 @stat(i8* %5, %struct.stat* %3)
%7 = icmp sge i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 2
%10 = load i32, i32* %9
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %14, i32 %16)
br label %22
18: ; preds = %0
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %8
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [48 x i8] c"blksize: %ld, allocated 512B num: %ld, dev: %ld\00"
@.str.2 = [40 x i8] c"get stat of file error!error reason: %s\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @memset(%struct.stat* %1, i32 0, i32 12)
%4 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%5 = icmp sgt i64 %4, -1
br i1 %5, label %6, label %16
6: ; preds = %0
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %12, i32 %14)
br label %20
16: ; preds = %0
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %6
ret i32 0
}