#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 O_CREAT;
int O_RDWR;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = -1;
  int file_size = 20000;
  char *buf = NULL;
  if (argc != 2) {
    printf("Usage: %s /cluster2/test/FileName\n", argv[0]);
    exit(1);
  }
  if (strncmp("/cluster2/test", argv[1], 14)) {
    printf("Please input FilePath: /cluster2/test\n");
    exit(1);
  }
  buf = calloc(10240, sizeof(char));
  if (!buf) {
    perror("calloc()");
    exit(-1);
  }
  memset(buf, '*', 10240);
  buf[10240 - 1] = '\n';
  fd = open(argv[1], O_RDWR | O_CREAT, 0644);
  if (fd == -1) {
    perror("open()");
    exit(-1);
  }
  while (--file_size) {
    if (write(fd, buf, 10240) != 10240) {
      perror("write()");
      break;
    }
  }
  close(fd);
  if (buf)
    free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x4e20,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f5 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0xe,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1230 <main+0x90>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x2800,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1264 <main+0xc4>
lea    0xe04(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2a,%esi
mov    $0x2800,%edx
call   1070 <memset@plt>
mov    -0x20(%rbp),%rax
movb   $0xa,0x27ff(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    0x2d5e(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c9 <main+0x129>
lea    0xda8(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
jmp    12ce <main+0x12e>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1312 <main+0x172>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x2800,%edx
call   1050 <write@plt>
cmp    $0x2800,%eax
je     130d <main+0x16d>
lea    0xd66(%rip),%rdi
call   10b0 <perror@plt>
jmp    1312 <main+0x172>
jmp    12ce <main+0x12e>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmpq   $0x0,-0x20(%rbp)
je     132e <main+0x18e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1292 <main+0xe2>
mov    0x8(%r14),%rsi
lea    0xe84(%rip),%rdi
mov    $0xe,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    12ad <main+0xfd>
mov    $0x2800,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
test   %rax,%rax
je     12c3 <main+0x113>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x2a,%esi
mov    $0x2800,%edx
call   1080 <memset@plt>
movb   $0xa,0x27ff(%r15)
0a
mov    0x8(%r14),%rdi
mov    0x2dbf(%rip),%rax
mov    0x2dd0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12cc <main+0x11c>
mov    %eax,%ebp
mov    $0xffffb1e0,%ebx
cs nopw 0x0(%rax,%rax,1)
inc    %ebx
je     1276 <main+0xc6>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2800,%edx
call   1060 <write@plt>
cmp    $0x2800,%eax
je     1250 <main+0xa0>
lea    0xdc2(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xd64(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd87(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd59(%rip),%rdi
jmp    12d3 <main+0x123>
lea    0xd59(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"Usage: %s /cluster2/test/FileName\0A\00"
@.str.1 = [15 x i8] c"/cluster2/test\00"
@.str.2 = [39 x i8] c"Please input FilePath: /cluster2/test\0A\00"
@.str.3 = [9 x i8] c"calloc()\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.4 = [7 x i8] c"open()\00"
@.str.5 = [8 x i8] c"write()\00"
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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 20000, i32* %7
store i8* null, i8** %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 14)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = call i8* @calloc(i32 10240, i32 1)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %26
%34 = load i8*, i8** %8
%35 = call i32 @memset(i8* %34, i8 signext 42, i32 10240)
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 10239
store i8 10, i8* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDWR
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = call i32 @open(i8* %40, i32 %43, i32 420)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %33
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %33
br label %51
51: ; preds = %62, %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, -1
store i32 %53, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %51
%56 = load i32, i32* %6
%57 = load i8*, i8** %8
%58 = call i32 @write(i32 %56, i8* %57, i32 10240)
%59 = icmp ne i32 %58, 10240
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %63
62: ; preds = %55
br label %51
63: ; preds = %60, %51
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
%66 = load i8*, i8** %8
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %68, %63
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Usage: %s /cluster2/test/FileName\0A\00"
@.str.1 = [15 x i8] c"/cluster2/test\00"
@.str.3 = [9 x i8] c"calloc()\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.4 = [7 x i8] c"open()\00"
@.str.5 = [8 x i8] c"write()\00"
@str = [38 x i8] c"Please input FilePath: /cluster2/test\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 14)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = tail call dereferenceable_or_null(10240) i8* @calloc(i32 10240, i32 1)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %16
%23 = tail call i32 @memset(i8* %17, i8 signext 42, i32 10240)
%24 = getelementptr inbounds i8, i8* %17, i64 10239
store i8 10, i8* %24
%25 = load i8*, i8** %9
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = tail call i32 @open(i8* %25, i32 %28, i32 420)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @exit(i32 -1)
unreachable
34: ; preds = %22, %38
%35 = phi i32 [ %36, %38 ], [ 20000, %22 ]
%36 = add nsw i32 %35, -1
%37 = icmp eq i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %34
%39 = tail call i32 @write(i32 %29, i8* %17, i32 10240)
%40 = icmp eq i32 %39, 10240
br i1 %40, label %34, label %41
41: ; preds = %38
%42 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %34, %41
%44 = tail call i32 @close(i32 %29)
%45 = tail call i32 @free(i8* %17)
ret i32 0
}