#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s name size\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char *name = argv[1];
  unsigned int size = atoi(argv[2]) * 1024 * 1024;
  int fd =
      open(name, O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU | S_IRGRP | S_IROTH);
  if (fd == -1) {
    fprintf(stderr, "Cannot create %s: %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  int i;
  char c = 'A';
  for (i = 0; i < size; ++i) {
    if (write(fd, &c, 1) != 1) {
      close(fd);
      fprintf(stderr, "Cannot write data: %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bc <main+0x4c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
or     (%rax),%esi
mov    0x2df5(%rip),%rax
or     (%rax),%esi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    0x2dab(%rip),%rax
or     (%rax),%edx
mov    0x2d9a(%rip),%rax
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1272 <main+0x102>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movb   $0x41,-0x25(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    12fa <main+0x18a>
mov    -0x20(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     12e7 <main+0x177>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12ec <main+0x17c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127d <main+0x10d>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    126a <main+0xfa>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    0x2e63(%rip),%rcx
mov    0x2dfc(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    0x2e49(%rip),%rcx
or     (%rcx),%esi
mov    0x2e28(%rip),%rcx
mov    0x2e01(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,%ebp
mov    0x2dec(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     127f <main+0x10f>
mov    %eax,%ebx
movb   $0x41,0xf(%rsp)
test   %ebp,%ebp
je     1219 <main+0xa9>
shl    $0x14,%ebp
cmp    $0x2,%ebp
mov    $0x1,%eax
cmovb  %eax,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    122b <main+0xbb>
add    $0xffffffff,%ebp
jne    1200 <main+0x90>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xddb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd83(%rip),%rsi
jmp    1255 <main+0xe5>
mov    0x2d42(%rip),%rax
mov    (%rax),%ebx
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd78(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    125c <main+0xec>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s name size\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [22 x i8] c"Cannot create %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Cannot write data: %s\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 i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = mul nsw i32 %28, 1024
%30 = mul nsw i32 %29, 1024
store i32 %30, i32* %7
%31 = load i8*, i8** %6
%32 = load i32, i32* @O_CREAT
%33 = load i32, i32* @O_WRONLY
%34 = or i32 %32, %33
%35 = load i32, i32* @O_TRUNC
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IRWXU
%38 = load i32, i32* @S_IRGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IROTH
%41 = or i32 %39, %40
%42 = call i32 @open(i8* %31, i32 %36, i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %53
45: ; preds = %21
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %6
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %21
store i8 65, i8* %10
store i32 0, i32* %9
br label %54
54: ; preds = %72, %53
%55 = load i32, i32* %9
%56 = load i32, i32* %7
%57 = icmp ult i32 %55, %56
br i1 %57, label %58, label %75
58: ; preds = %54
%59 = load i32, i32* %8
%60 = call i32 @write(i32 %59, i8* %10, i32 1)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %71
62: ; preds = %58
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %58
br label %72
72: ; preds = %71
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %54
75: ; preds = %54
%76 = load i32, i32* %8
%77 = call i32 @close(i32 %76)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s name size\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [22 x i8] c"Cannot create %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Cannot write data: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 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
%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 i32 @atoi(i8* %15)
%17 = shl i32 %16, 20
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* @O_WRONLY
%20 = or i32 %19, %18
%21 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRWXU
%24 = load i32, i32* @S_IRGRP
%25 = or i32 %24, %23
%26 = load i32, i32* @S_IROTH
%27 = or i32 %25, %26
%28 = tail call i32 @open(i8* %13, i32 %22, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %37
30: ; preds = %11
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %11
store i8 65, i8* %3
%38 = icmp eq i32 %16, 0
br i1 %38, label %56, label %39
39: ; preds = %37
%40 = call i32 @llvm.umax.i32(i32 %17, i32 1)
br label %43
41: ; preds = %43
%42 = icmp eq i32 %47, %40
br i1 %42, label %56, label %43
43: ; preds = %39, %41
%44 = phi i32 [ %47, %41 ], [ 0, %39 ]
%45 = call i32 @write(i32 %28, i8* %3, i32 1)
%46 = icmp eq i32 %45, 1
%47 = add nuw i32 %44, 1
br i1 %46, label %41, label %48
48: ; preds = %43
%49 = tail call i32 @close(i32 %28)
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = tail call i8* @strerror(i32 %51)
%53 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
56: ; preds = %41, %37
%57 = tail call i32 @close(i32 %28)
ret i32 0
}