#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 scalar_t__ uint64_t;
typedef int time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int time(int /*<<< orphan*/ *);
int main(void) {
  FILE *fp = NULL;
  time_t prev = 0, cur = 0;
  uint64_t wrtsize = 0, totalsize = 1024 * 1024 * 1024;
  char *fname = "aaa.txt";
  char content[4096] = {0};
  fp = fopen(fname, "a+");
  if (fp == NULL)
    return 0;
  prev = time(NULL);
  while (wrtsize < totalsize) {
    fwrite(content, 1, 4096, fp);
    wrtsize += 100;
  }
  cur = time(NULL);
  printf(">>>>>use %d second\r\n", cur - prev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x40000000,-0x28(%rbp)
40
lea    0xe71(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d1 <main+0x81>
movl   $0x0,-0x4(%rbp)
jmp    123b <main+0xeb>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1216 <main+0xc6>
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rax
add    $0x64,%rax
mov    %rax,-0x20(%rbp)
jmp    11dd <main+0x8d>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
sub    -0x14(%rbp),%esi
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe8d(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11da <main+0x8a>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%r14d
mov    $0xffffffffffffff9c,%rbp
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0x64,%rbp
cmp    $0x3fffff9c,%rbp
jb     11a0 <main+0x50>
xor    %edi,%edi
call   1050 <time@plt>
sub    %r14d,%eax
lea    0xe38(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"aaa.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [21 x i8] c">>>>>use %d second\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [4096 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i64 0, i64* %5
store i64 1073741824, i64* %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = bitcast [4096 x i8]* %8 to i8*
%10 = load i8*, i8** %7
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 0, i32* %1
br label %33
15: ; preds = %0
%16 = call i32 @time(i32* null)
store i32 %16, i32* %3
br label %17
17: ; preds = %21, %15
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = call i32 @fwrite(i8* %22, i32 1, i32 4096, i32* %23)
%25 = load i64, i64* %5
%26 = add nsw i64 %25, 100
store i64 %26, i64* %5
br label %17
27: ; preds = %17
%28 = call i32 @time(i32* null)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = sub nsw i32 %29, %30
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
store i32 0, i32* %1
br label %33
33: ; preds = %27, %14
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [8 x i8] c"aaa.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [21 x i8] c">>>>>use %d second\0D\0A\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = tail call i32 @time(i32* null)
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %10, %7 ]
%9 = call i32 @fwrite(i8* %2, i32 1, i32 4096, i32* %3)
%10 = add nuw nsw i64 %8, 100
%11 = icmp ult i64 %8, 1073741724
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = tail call i32 @time(i32* null)
%14 = sub nsw i32 %13, %6
%15 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %0, %12
ret i32 0
}