#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__ time_t;
struct tms {
  scalar_t__ tms_stime;
  scalar_t__ tms_utime;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ctime(scalar_t__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fsync(int);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
scalar_t__ times(struct tms *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char fn[100];
  char buffer[1024];
  int blocks, i, fd, tag, j;
  struct tms tbuf;
  time_t start, end;
  long ut, st, dur;
  char hostname[100];
  clock_t alpha, omega;
  tag = atoi(argv[1]);
  sprintf(fn, "bytes%04d.txt", tag);
  blocks = atoi(argv[2]);
  for (i = 0; i < 1024; i++) {
    buffer[i] = '0';
  }
  start = time(NULL);
  fd = open(fn, O_WRONLY | O_CREAT, 0644);
  alpha = times(&tbuf);
  for (i = 0; i < blocks; i++) {
    for (j = 0; j < 1048576; j++) {
      write(fd, buffer, 1024);
    }
    fsync(fd);
    lseek(fd, 0, SEEK_SET);
    omega = times(&tbuf);
    fprintf(stderr, "%ld\n", (long)(omega - alpha));
    alpha = omega;
  }
  fsync(fd);
  close(fd);
  end = time(NULL);
  times(&tbuf);
  ut = (long)tbuf.tms_utime;
  st = (long)tbuf.tms_stime;
  dur = (long)(end - start);
  gethostname(hostname, 100);
  fprintf(stderr, "\tElapsed\tUTime\tSTime\tTag\tBlocks\tHost\tStart\n");
  fprintf(stderr, "GDB\t%ld\t%ld\t%ld\t%d\t%d\t%s\t%s", dur, ut, st, tag,
          blocks, hostname, ctime(&start));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x490(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x490(%rbp),%edx
lea    0xe03(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x484(%rbp)
movl   $0x0,-0x488(%rbp)
cmpl   $0x400,-0x488(%rbp)
jge    1252 <main+0x92>
movslq -0x488(%rbp),%rax
movb   $0x30,-0x480(%rbp,%rax,1)
30
mov    -0x488(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x488(%rbp)
jmp    121f <main+0x5f>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0x4b0(%rbp)
lea    -0x80(%rbp),%rdi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x48c(%rbp)
lea    -0x4a8(%rbp),%rdi
call   10b0 <times@plt>
mov    %rax,-0x548(%rbp)
movl   $0x0,-0x488(%rbp)
mov    -0x488(%rbp),%eax
cmp    -0x484(%rbp),%eax
jge    1377 <main+0x1b7>
movl   $0x0,-0x494(%rbp)
cmpl   $0x100000,-0x494(%rbp)
jge    12fc <main+0x13c>
mov    -0x48c(%rbp),%edi
lea    -0x480(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    -0x494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x494(%rbp)
jmp    12c1 <main+0x101>
mov    -0x48c(%rbp),%edi
call   1090 <fsync@plt>
mov    -0x48c(%rbp),%edi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
lea    -0x4a8(%rbp),%rdi
call   10b0 <times@plt>
mov    %rax,-0x550(%rbp)
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
mov    -0x550(%rbp),%rdx
sub    -0x548(%rbp),%rdx
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x550(%rbp),%rax
mov    %rax,-0x548(%rbp)
mov    -0x488(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x488(%rbp)
jmp    12a5 <main+0xe5>
mov    -0x48c(%rbp),%edi
call   1090 <fsync@plt>
mov    -0x48c(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0x4b8(%rbp)
lea    -0x4a8(%rbp),%rdi
call   10b0 <times@plt>
mov    -0x4a0(%rbp),%rax
mov    %rax,-0x4c0(%rbp)
mov    -0x4a8(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
mov    -0x4b8(%rbp),%rax
sub    -0x4b0(%rbp),%rax
mov    %rax,-0x4d0(%rbp)
lea    -0x540(%rbp),%rdi
mov    $0x64,%esi
call   10d0 <gethostname@plt>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc18(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x57c(%rbp)
mov    -0x4d0(%rbp),%rax
mov    %rax,-0x578(%rbp)
mov    -0x4c0(%rbp),%rax
mov    %rax,-0x570(%rbp)
mov    -0x4c8(%rbp),%rax
mov    %rax,-0x568(%rbp)
mov    -0x490(%rbp),%eax
mov    %eax,-0x560(%rbp)
mov    -0x484(%rbp),%eax
mov    %eax,-0x55c(%rbp)
lea    -0x540(%rbp),%rax
mov    %rax,-0x558(%rbp)
lea    -0x4b0(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x57c(%rbp),%edi
mov    -0x578(%rbp),%rdx
mov    -0x570(%rbp),%rcx
mov    -0x568(%rbp),%r8
mov    -0x560(%rbp),%r9d
mov    -0x55c(%rbp),%r11d
mov    -0x558(%rbp),%r10
lea    0xb9b(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x5a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10d0 <atoi@plt>
lea    0xe0c(%rip),%rsi
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
mov    %eax,0x4(%rsp)
mov    %eax,%edx
call   10f0 <sprintf@plt>
mov    0x10(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebx
lea    0x110(%rsp),%rdi
mov    $0x400,%edx
mov    $0x30,%esi
call   1060 <memset@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x20(%rsp)
mov    %rax,0x28(%rsp)
mov    0x2d7c(%rip),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
call   10b0 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
call   10c0 <times@plt>
mov    %rbx,0x8(%rsp)
test   %ebx,%ebx
jle    1305 <main+0x135>
mov    %rax,%r12
lea    0x110(%rsp),%r14
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x100000,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
jne    12a0 <main+0xd0>
mov    %ebp,%edi
call   10a0 <fsync@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0x10(%rsp),%rdi
call   10c0 <times@plt>
mov    %rax,%r15
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rdx
sub    %r12,%rdx
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r13d
mov    %r15,%r12
cmp    0x8(%rsp),%r13d
jne    1290 <main+0xc0>
mov    %ebp,%edi
call   10a0 <fsync@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
call   10c0 <times@plt>
mov    0x10(%rsp),%r15
mov    0x18(%rsp),%r12
sub    0x20(%rsp),%rbx
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   10e0 <gethostname@plt>
mov    0x2c89(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xcba(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%rbp),%ebp
lea    0x28(%rsp),%rdi
call   1040 <ctime@plt>
mov    %eax,%r10d
sub    $0x8,%rsp
lea    0xcc4(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    0xc(%rsp),%r9d
xor    %eax,%eax
push   %r10
push   %r14
push   0x20(%rsp)
call   1080 <fprintf@plt>
add    $0x20,%rsp
xor    %eax,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@.str = [14 x i8] c"bytes%04d.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [44 x i8] c"\09Elapsed\09UTime\09STime\09Tag\09Blocks\09Host\09Start\0A\00"
@.str.3 = [28 x i8] c"GDB\09%ld\09%ld\09%ld\09%d\09%d\09%s\09%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.tms
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca [100 x i8]
%20 = alloca i64
%21 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %11
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %11
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %8
store i32 0, i32* %9
br label %33
33: ; preds = %40, %2
%34 = load i32, i32* %9
%35 = icmp slt i32 %34, 1024
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %38
store i8 48, i8* %39
br label %40
40: ; preds = %36
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %33
43: ; preds = %33
%44 = call i64 @time(i32* null)
store i64 %44, i64* %14
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* @O_WRONLY
%47 = load i32, i32* @O_CREAT
%48 = or i32 %46, %47
%49 = call i32 @open(i8* %45, i32 %48, i32 420)
store i32 %49, i32* %10
%50 = call i64 @times(%struct.tms* %13)
store i64 %50, i64* %20
store i32 0, i32* %9
br label %51
51: ; preds = %79, %43
%52 = load i32, i32* %9
%53 = load i32, i32* %8
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %82
55: ; preds = %51
store i32 0, i32* %12
br label %56
56: ; preds = %63, %55
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, 1048576
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i32, i32* %10
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%62 = call i32 @write(i32 %60, i8* %61, i32 1024)
br label %63
63: ; preds = %59
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %56
66: ; preds = %56
%67 = load i32, i32* %10
%68 = call i32 @fsync(i32 %67)
%69 = load i32, i32* %10
%70 = load i32, i32* @SEEK_SET
%71 = call i32 @lseek(i32 %69, i32 0, i32 %70)
%72 = call i64 @times(%struct.tms* %13)
store i64 %72, i64* %21
%73 = load i32, i32* @stderr
%74 = load i64, i64* %21
%75 = load i64, i64* %20
%76 = sub nsw i64 %74, %75
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %76)
%78 = load i64, i64* %21
store i64 %78, i64* %20
br label %79
79: ; preds = %66
%80 = load i32, i32* %9
%81 = add nsw i32 %80, 1
store i32 %81, i32* %9
br label %51
82: ; preds = %51
%83 = load i32, i32* %10
%84 = call i32 @fsync(i32 %83)
%85 = load i32, i32* %10
%86 = call i32 @close(i32 %85)
%87 = call i64 @time(i32* null)
store i64 %87, i64* %15
%88 = call i64 @times(%struct.tms* %13)
%89 = getelementptr inbounds %struct.tms, %struct.tms* %13, i32 0, i32 1
%90 = load i64, i64* %89
store i64 %90, i64* %16
%91 = getelementptr inbounds %struct.tms, %struct.tms* %13, i32 0, i32 0
%92 = load i64, i64* %91
store i64 %92, i64* %17
%93 = load i64, i64* %15
%94 = load i64, i64* %14
%95 = sub nsw i64 %93, %94
store i64 %95, i64* %18
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%97 = call i32 @gethostname(i8* %96, i32 100)
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%100 = load i32, i32* @stderr
%101 = load i64, i64* %18
%102 = load i64, i64* %16
%103 = load i64, i64* %17
%104 = load i32, i32* %11
%105 = load i32, i32* %8
%106 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%107 = call i32 @ctime(i64* %14)
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 %101, i64 %102, i64 %103, i32 %104, i32 %105, i8* %106, i32 %107)
ret i32 0
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@.str = [14 x i8] c"bytes%04d.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [44 x i8] c"\09Elapsed\09UTime\09STime\09Tag\09Blocks\09Host\09Start\0A\00"
@.str.3 = [28 x i8] c"GDB\09%ld\09%ld\09%ld\09%d\09%d\09%s\09%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = alloca %struct.tms
%7 = alloca i64
%8 = alloca [100 x i8]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = bitcast %struct.tms* %6 to i8*
%12 = bitcast i64* %7 to i8*
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i64 @time(i32* null)
store i64 %21, i64* %7
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = call i32 @open(i8* %9, i32 %24, i32 420)
%26 = call i64 @times(%struct.tms* %6)
%27 = icmp sgt i32 %20, 0
br i1 %27, label %28, label %46
28: ; preds = %2, %36
%29 = phi i32 [ %44, %36 ], [ 0, %2 ]
%30 = phi i64 [ %40, %36 ], [ %26, %2 ]
br label %31
31: ; preds = %28, %31
%32 = phi i32 [ 0, %28 ], [ %34, %31 ]
%33 = call i32 @write(i32 %25, i8* %10, i32 1024)
%34 = add nuw nsw i32 %32, 1
%35 = icmp eq i32 %34, 1048576
br i1 %35, label %36, label %31
36: ; preds = %31
%37 = tail call i32 @fsync(i32 %25)
%38 = load i32, i32* @SEEK_SET
%39 = tail call i32 @lseek(i32 %25, i32 0, i32 %38)
%40 = call i64 @times(%struct.tms* %6)
%41 = load i32, i32* @stderr
%42 = sub nsw i64 %40, %30
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %42)
%44 = add nuw nsw i32 %29, 1
%45 = icmp eq i32 %44, %20
br i1 %45, label %46, label %28
46: ; preds = %36, %2
%47 = tail call i32 @fsync(i32 %25)
%48 = tail call i32 @close(i32 %25)
%49 = tail call i64 @time(i32* null)
%50 = call i64 @times(%struct.tms* %6)
%51 = getelementptr inbounds %struct.tms, %struct.tms* %6, i64 0, i32 1
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.tms, %struct.tms* %6, i64 0, i32 0
%54 = load i64, i64* %53
%55 = sub nsw i64 %49, %21
%56 = call i32 @gethostname(i8* %13, i32 100)
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* @stderr
%60 = call i32 @ctime(i64* %7)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 %55, i64 %52, i64 %54, i32 %16, i32 %20, i8* %13, i32 %60)
ret i32 0
}