#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 */
typedef int uint64_t;
struct statvfs {
  scalar_t__ f_frsize;
  scalar_t__ f_bavail;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int statvfs(char *, struct statvfs *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  char *dir_name = ".";
  uint64_t free_space;
  struct statvfs fs_info;
  if (argc > 1) {
    if (strncmp(argv[1], "--help", 6) == 0 || strncmp(argv[1], "-h", 2) == 0) {
      printf("Usage is: "
             "free_space [directory]\n"
             "\n"
             "Display the free space of the file system "
             "of the directory given\n"
             "or the current directory if no "
             "directory is given.\nThe value output is "
             "in bytes.\n");
      return 1;
    }
    dir_name = argv[1];
  }
  if (statvfs(dir_name, &fs_info) == -1)
    return 1;
  free_space = (uint64_t)fs_info.f_bavail * (uint64_t)fs_info.f_frsize;
  printf("%llu\n", (unsigned long long)free_space);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a1 <main+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11bb <main+0x8b>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xe0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <statvfs@plt>
cmp    $0xffffffff,%eax
jne    11e9 <main+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xe0>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   %ecx,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     1187 <main+0x47>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea8(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b8 <main+0x78>
mov    0x8(%rbx),%rdi
lea    0xe95(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b8 <main+0x78>
mov    0x8(%rbx),%rdi
jmp    118e <main+0x4e>
lea    0xf34(%rip),%rdi
mov    %rsp,%rsi
call   1060 <statvfs@plt>
cmp    $0xffffffff,%eax
je     11c4 <main+0x84>
mov    0x8(%rsp),%eax
imul   (%rsp),%eax
movslq %eax,%rsi
lea    0xe5d(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c9 <main+0x89>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.statvfs = type { i64, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"-h\00"
@.str.3 = [181 x i8] c"Usage is: free_space [directory]\0A\0ADisplay the free space of the file system of the directory given\0Aor the current directory if no directory is given.\0AThe value output is in bytes.\0A\00"
@.str.4 = [6 x i8] c"%llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.statvfs
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %29
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17, %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %45
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
br label %29
29: ; preds = %25, %2
%30 = load i8*, i8** %6
%31 = call i32 @statvfs(i8* %30, %struct.statvfs* %8)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %3
br label %45
34: ; preds = %29
%35 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %8, i32 0, i32 1
%36 = load i64, i64* %35
%37 = trunc i64 %36 to i32
%38 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %8, i32 0, i32 0
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i32
%41 = mul nsw i32 %37, %40
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %34, %33, %23
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.statvfs = type { i64, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"-h\00"
@.str.4 = [6 x i8] c"%llu\0A\00"
@str = [180 x i8] c"Usage is: free_space [directory]\0A\0ADisplay the free space of the file system of the directory given\0Aor the current directory if no directory is given.\0AThe value output is in bytes.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.statvfs
%4 = bitcast %struct.statvfs* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11, %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([180 x i8], [180 x i8]* @str, i64 0, i64 0))
br label %32
17: ; preds = %11
%18 = load i8*, i8** %7
br label %19
19: ; preds = %17, %2
%20 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%21 = call i32 @statvfs(i8* %20, %struct.statvfs* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %32, label %23
23: ; preds = %19
%24 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.statvfs, %struct.statvfs* %3, i64 0, i32 0
%27 = load i64, i64* %26
%28 = shl i64 %25, 32
%29 = mul i64 %28, %27
%30 = ashr exact i64 %29, 32
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %19, %23, %15
%33 = phi i32 [ 1, %15 ], [ 0, %23 ], [ 1, %19 ]
ret i32 %33
}