#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 EXIT_FAILURE;
int EXIT_SUCCESS;
void *atoi(char *);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ fill_buf(char *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, size_t);
int main(int argc, char **argv) {
  int fd = -1;
  char *buffer = NULL;
  size_t size = 104857600;
  int i = 0, loop = 0;
  if (argc < 3) {
    fprintf(stderr, "usage test4 [file_path] [size] [loop]\n");
    return EXIT_FAILURE;
  }
  if (-1 == (fd = creat(argv[1], 0600))) {
    perror("open");
    return EXIT_FAILURE;
  }
  size = atoi(argv[2]);
  loop = atoi(argv[3]);
  printf("file size = %ld\n", size);
  printf("loop = %d\n", loop);
  if (NULL == (buffer = malloc(size))) {
    perror("malloc");
    return EXIT_FAILURE;
  }
  for (i = 0; i < loop; i++) {
    int ret = 0;
    fill_buf(buffer, size);
    if (0 != (ret = write(fd, buffer, size * sizeof(char)))) {
      printf("write %d data\n", ret);
    }
  }
  close(fd);
  return EXIT_SUCCESS;
}


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)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x6400000,-0x28(%rbp)
06
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fb <main+0x6b>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <main+0x1a6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x180,%esi
call   10b0 <creat@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    123c <main+0xac>
lea    0xe01(%rip),%rdi
call   1090 <perror@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <main+0x1a6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    12b6 <main+0x126>
lea    0xda8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <main+0x1a6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1322 <main+0x192>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <fill_buf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
shl    $0x0,%rdx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     130f <main+0x17f>
mov    -0x34(%rbp),%esi
lea    0xd45(%rip),%rdi
call   1040 <printf@plt>
jmp    1314 <main+0x184>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12bd <main+0x12d>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jg     11be <main+0x2e>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e1f(%rip),%rax
jmp    126d <main+0xdd>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    $0x180,%esi
call   10b0 <creat@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0xe8>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rax,%rbp
lea    0xe32(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1281 <main+0xf1>
test   %ebp,%ebp
jle    125e <main+0xce>
mov    %rax,%rbx
lea    0xe24(%rip),%r12
jmp    1235 <main+0xa5>
nopl   (%rax)
add    $0xffffffff,%ebp
je     125e <main+0xce>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <fill_buf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <write@plt>
test   %eax,%eax
je     1230 <main+0xa0>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
jmp    1230 <main+0xa0>
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda8(%rip),%rdi
jmp    1288 <main+0xf8>
lea    0xdc0(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d44(%rip),%rax
jmp    126d <main+0xdd>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage test4 [file_path] [size] [loop]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [17 x i8] c"file size = %ld\0A\00"
@.str.3 = [11 x i8] c"loop = %d\0A\00"
@.str.4 = [7 x i8] c"malloc\00"
@.str.5 = [15 x i8] c"write %d data\0A\00"
@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 i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i8* null, i8** %7
store i64 104857600, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %75
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @creat(i8* %21, i32 384)
store i32 %22, i32* %6
%23 = icmp eq i32 -1, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %75
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i8* @atoi(i8* %30)
%32 = ptrtoint i8* %31 to i64
store i64 %32, i64* %8
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i8* @atoi(i8* %35)
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %10
%38 = load i64, i64* %8
%39 = trunc i64 %38 to i32
%40 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %10
%42 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i64, i64* %8
%44 = call i8* @malloc(i64 %43)
store i8* %44, i8** %7
%45 = icmp eq i8* null, %44
br i1 %45, label %46, label %49
46: ; preds = %27
%47 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %75
49: ; preds = %27
store i32 0, i32* %9
br label %50
50: ; preds = %68, %49
%51 = load i32, i32* %9
%52 = load i32, i32* %10
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %71
54: ; preds = %50
store i32 0, i32* %11
%55 = load i8*, i8** %7
%56 = load i64, i64* %8
%57 = call i32 @fill_buf(i8* %55, i64 %56)
%58 = load i32, i32* %6
%59 = load i8*, i8** %7
%60 = load i64, i64* %8
%61 = mul i64 %60, 1
%62 = call i32 @write(i32 %58, i8* %59, i64 %61)
store i32 %62, i32* %11
%63 = icmp ne i32 0, %62
br i1 %63, label %64, label %67
64: ; preds = %54
%65 = load i32, i32* %11
%66 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %54
br label %68
68: ; preds = %67
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %50
71: ; preds = %50
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* @EXIT_SUCCESS
store i32 %74, i32* %3
br label %75
75: ; preds = %71, %46, %24, %14
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"usage test4 [file_path] [size] [loop]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [17 x i8] c"file size = %ld\0A\00"
@.str.3 = [11 x i8] c"loop = %d\0A\00"
@.str.4 = [7 x i8] c"malloc\00"
@.str.5 = [15 x i8] c"write %d data\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %45
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @creat(i8* %9, i32 384)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %45
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i8* @atoi(i8* %16)
%18 = ptrtoint i8* %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i8* @atoi(i8* %20)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i32
%24 = trunc i64 %18 to i32
%25 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%27 = tail call i8* @malloc(i64 %18)
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %14
%30 = icmp sgt i32 %23, 0
br i1 %30, label %33, label %43
31: ; preds = %14
%32 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %45
33: ; preds = %29, %40
%34 = phi i32 [ %41, %40 ], [ 0, %29 ]
%35 = tail call i32 @fill_buf(i8* %27, i64 %18)
%36 = tail call i32 @write(i32 %10, i8* %27, i64 %18)
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %40
40: ; preds = %38, %33
%41 = add nuw nsw i32 %34, 1
%42 = icmp eq i32 %41, %23
br i1 %42, label %43, label %33
43: ; preds = %40, %29
%44 = tail call i32 @close(i32 %10)
br label %45
45: ; preds = %43, %31, %12, %4
%46 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %12 ], [ @EXIT_FAILURE, %31 ], [ @EXIT_SUCCESS, %43 ]
%47 = load i32, i32* %46
ret i32 %47
}