#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ handle_fatal_error_and_exit(char *);
int /*<<< orphan*/ lseek(int, size_t, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char *argv[]) {
  int fd;
  int zero;
  char *filename;
  size_t length;
  if (argc != 3) {
    printf("Usage: %s <filename> <number of gigabytes>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  zero = 0;
  filename = argv[1];
  length = (size_t)atoi(argv[2]) * 1024 * 1024 * 1024;
  fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
  if (fd == -1) {
    handle_fatal_error_and_exit("Error opening a file.\n");
  }
  lseek(fd, length - 1, SEEK_SET);
  write(fd, &zero, 1);
  close(fd);
  exit(EXIT_SUCCESS);
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
shl    $0xa,%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    0x2df3(%rip),%rax
or     (%rax),%esi
mov    0x2dca(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1233 <main+0xb3>
lea    0xdfe(%rip),%rdi
call   1070 <handle_fatal_error_and_exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1220 <main+0xa0>
movl   $0x0,0x4(%rsp)
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
call   1090 <atoi@plt>
mov    0x2e08(%rip),%rcx
mov    0x2e49(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %rax,%rbx
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11df <main+0x5f>
lea    0xe52(%rip),%rdi
call   1070 <handle_fatal_error_and_exit@plt>
shl    $0x1e,%rbx
add    $0xffffffffffffffff,%rbx
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <lseek@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    (%rsi),%rsi
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Usage: %s <filename> <number of gigabytes>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [23 x i8] c"Error opening a file.\0A\00"
@SEEK_SET = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
store i32 0, i32* %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @atoi(i8* %25)
%27 = mul i64 %26, 1024
%28 = mul i64 %27, 1024
%29 = mul i64 %28, 1024
store i64 %29, i64* %9
%30 = load i8*, i8** %8
%31 = load i32, i32* @O_WRONLY
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = load i32, i32* @O_EXCL
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %30, i32 %35, i32 438)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %19
%40 = call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %19
%42 = load i32, i32* %6
%43 = load i64, i64* %9
%44 = sub i64 %43, 1
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @lseek(i32 %42, i64 %44, i32 %45)
%47 = load i32, i32* %6
%48 = call i32 @write(i32 %47, i32* %7, i32 1)
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
unreachable
}

LLVM IR (-O2):
@.str = [44 x i8] c"Usage: %s <filename> <number of gigabytes>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [23 x i8] c"Error opening a file.\0A\00"
@SEEK_SET = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
store i32 0, i32* %3
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i64 @atoi(i8* %15)
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @O_EXCL
%21 = or i32 %19, %20
%22 = tail call i32 @open(i8* %13, i32 %21, i32 438)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = tail call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
%27 = shl i64 %16, 30
%28 = add i64 %27, -1
%29 = load i32, i32* @SEEK_SET
%30 = tail call i32 @lseek(i32 %22, i64 %28, i32 %29)
%31 = call i32 @write(i32 %22, i32* %3, i32 1)
%32 = tail call i32 @close(i32 %22)
%33 = load i32, i32* @EXIT_SUCCESS
%34 = tail call i32 @exit(i32 %33)
unreachable
}