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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ check_a_file(char *, int, int);
int /*<<< orphan*/ delete_file(char *);
int /*<<< orphan*/ exit_failure();
int /*<<< orphan*/ exit_success();
scalar_t__ getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ write_a_file(char *, int, int);
int main(int argc, char *argv[]) {
  int gigs = 1;
  char file[1024] = {'\0'};
  if (argc == 2) {
    gigs = atoi(argv[1]);
    if (gigs == 0 || gigs < 0) {
      printf("Please supply a natural number of gigs.\n");
      exit_failure();
    }
  }
  sprintf(file, "./lfs-test.%u", (unsigned int)getpid());
  printf("sizeof int = %u\n", (unsigned int)sizeof(int));
  printf("sizeof off_t = %u\n", (unsigned int)sizeof(off_t));
  printf("sizeof long = %u\n", (unsigned int)sizeof(long));
  printf("sizeof long long = %u\n", (unsigned int)sizeof(long long));
  printf("Creating/Using file: %s\n", file);
  printf("Creating a %d gig file\n", gigs);
  write_a_file(file, 1024, (1024 * 1024) * gigs);
  printf("Verifying the %d gig file\n", gigs);
  check_a_file(file, 1024, (1024 * 1024) * gigs);
  delete_file(file);
  exit_success();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jne    121b <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1201 <main+0x61>
cmpl   $0x0,-0x14(%rbp)
jge    1216 <main+0x76>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <exit_failure@plt>
jmp    121b <main+0x7b>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x428(%rbp),%rdi
mov    %eax,%edx
lea    0xde9(%rip),%rsi
call   10c0 <sprintf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde9(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde9(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde8(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%edx
shl    $0x14,%edx
mov    $0x400,%esi
call   10b0 <write_a_file@plt>
mov    -0x14(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%edx
shl    $0x14,%edx
mov    $0x400,%esi
call   1080 <check_a_file@plt>
lea    -0x420(%rbp),%rdi
call   1030 <delete_file@plt>
mov    $0x0,%al
call   1060 <exit_success@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    $0x1,%ebx
cmp    $0x2,%ebp
jne    11fb <main+0x4b>
mov    0x8(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     11fb <main+0x4b>
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <exit_failure@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdf7(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%edx
call   10d0 <sprintf@plt>
lea    0xdf1(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdef(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdef(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdee(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%ebp
shl    $0x14,%ebp
mov    %r14,%rdi
mov    $0x400,%esi
mov    %ebp,%edx
call   10c0 <write_a_file@plt>
lea    0xdee(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %ebp,%edx
call   1090 <check_a_file@plt>
mov    %r14,%rdi
call   1030 <delete_file@plt>
xor    %eax,%eax
call   1070 <exit_success@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Please supply a natural number of gigs.\0A\00"
@.str.1 = [14 x i8] c"./lfs-test.%u\00"
@.str.2 = [17 x i8] c"sizeof int = %u\0A\00"
@.str.3 = [19 x i8] c"sizeof off_t = %u\0A\00"
@.str.4 = [18 x i8] c"sizeof long = %u\0A\00"
@.str.5 = [23 x i8] c"sizeof long long = %u\0A\00"
@.str.6 = [25 x i8] c"Creating/Using file: %s\0A\00"
@.str.7 = [24 x i8] c"Creating a %d gig file\0A\00"
@.str.8 = [27 x i8] c"Verifying the %d gig file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%8 = bitcast [1024 x i8]* %7 to i8*
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (...) @exit_failure()
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i64 (...) @getpid()
%28 = trunc i64 %27 to i32
%29 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 4)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 4)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 8)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 8)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = load i32, i32* %6
%40 = mul nsw i32 1048576, %39
%41 = call i32 @write_a_file(i8* %38, i32 1024, i32 %40)
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%45 = load i32, i32* %6
%46 = mul nsw i32 1048576, %45
%47 = call i32 @check_a_file(i8* %44, i32 1024, i32 %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%49 = call i32 @delete_file(i8* %48)
%50 = call i32 (...) @exit_success()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"./lfs-test.%u\00"
@.str.2 = [17 x i8] c"sizeof int = %u\0A\00"
@.str.3 = [19 x i8] c"sizeof off_t = %u\0A\00"
@.str.4 = [18 x i8] c"sizeof long = %u\0A\00"
@.str.5 = [23 x i8] c"sizeof long long = %u\0A\00"
@.str.6 = [25 x i8] c"Creating/Using file: %s\0A\00"
@.str.7 = [24 x i8] c"Creating a %d gig file\0A\00"
@.str.8 = [27 x i8] c"Verifying the %d gig file\0A\00"
@str = [40 x i8] c"Please supply a natural number of gigs.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 (...) @exit_failure()
br label %14
14: ; preds = %11, %6, %2
%15 = phi i32 [ %9, %11 ], [ %9, %6 ], [ 1, %2 ]
%16 = tail call i64 (...) @getpid()
%17 = trunc i64 %16 to i32
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 4)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 4)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 8)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 8)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %15)
%25 = shl nsw i32 %15, 20
%26 = call i32 @write_a_file(i8* %4, i32 1024, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %15)
%28 = call i32 @check_a_file(i8* %4, i32 1024, i32 %25)
%29 = call i32 @delete_file(i8* %4)
%30 = call i32 (...) @exit_success()
ret i32 0
}