#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 */
struct timeb {
  int time;
  int millitm;
};

/* Variables and functions */
int O_CREAT;
int O_SYNC;
int O_WRONLY;
long atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ftime(struct timeb *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  long megabytes, j, i;
  int outputfile;
  char buffer[(64 * 1024)];
  struct timeb before, after;
  if (argc != 3) {
    printf("Arguments are filename to create and size in megabytes\n");
    return -1;
  }
  for (j = 0; j < (64 * 1024); j++)
    buffer[j] = 'X';
  outputfile = open(argv[1], O_CREAT | O_WRONLY | O_SYNC);
  megabytes = atol(argv[2]);
  ftime(&before);
  for (i = 0; i < (((1024 * 1024) / (64 * 1024)) * megabytes); i++)
    write(outputfile, buffer, (64 * 1024));
  ftime(&after);
  long timetowrite =
      (after.time - before.time) * 1000 + (after.millitm - before.millitm);
  if (timetowrite > 0)
    printf("Bytes per millisecond written = %ld\n",
           ((1024 * 1024) * megabytes) / timetowrite);
  close(outputfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119d <main+0x3d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <main+0x16e>
movq   $0x0,-0x20(%rbp)
cmpq   $0x10000,-0x20(%rbp)
jge    11d0 <main+0x70>
mov    -0x20(%rbp),%rax
movb   $0x58,-0x10030(%rbp,%rax,1)
58
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
lea    -0x10038(%rbp),%rdi
call   1080 <ftime@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x4,%rcx
cmp    %rcx,%rax
jge    125a <main+0xfa>
mov    -0x2c(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    $0x10000,%edx
call   1030 <write@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1220 <main+0xc0>
lea    -0x10040(%rbp),%rdi
call   1080 <ftime@plt>
mov    -0x10040(%rbp),%eax
sub    -0x10038(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    -0x1003c(%rbp),%ecx
sub    -0x10034(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x10048(%rbp)
cmpq   $0x0,-0x10048(%rbp)
jle    12bf <main+0x15f>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
cqto
idivq  -0x10048(%rbp)
mov    %rax,%rsi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10018,%rsp
cmp    $0x3,%edi
jne    1260 <main+0xe0>
mov    %rsi,%r14
lea    0x10(%rsp),%rdi
mov    $0x10000,%edx
mov    $0x58,%esi
call   1060 <memset@plt>
mov    0x2e44(%rip),%rax
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%r14),%rdi
mov    0x2e16(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
call   1080 <atol@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
call   10a0 <ftime@plt>
test   %r14,%r14
jle    1226 <main+0xa6>
mov    %r14,%rax
shl    $0x4,%rax
cmp    $0x2,%rax
mov    $0x1,%ebp
cmovge %rax,%rbp
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x10000,%edx
call   1040 <write@plt>
add    $0xffffffffffffffff,%rbp
jne    1210 <main+0x90>
mov    %rsp,%rdi
call   10a0 <ftime@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%eax
sub    0x8(%rsp),%ecx
imul   $0x3e8,%ecx,%ecx
sub    0xc(%rsp),%eax
add    %ecx,%eax
jle    128b <main+0x10b>
mov    %eax,%ecx
shl    $0x14,%r14
mov    %r14,%rax
shr    $0x20,%rax
je     1273 <main+0xf3>
mov    %r14,%rax
cqto
idiv   %rcx
jmp    127a <main+0xfa>
lea    0xdbe(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1295 <main+0x115>
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
lea    0xd7f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i32 }
@.str = [56 x i8] c"Arguments are filename to create and size in megabytes\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [37 x i8] c"Bytes per millisecond written = %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca [65536 x i8]
%11 = alloca %struct.timeb
%12 = alloca %struct.timeb
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %81
18: ; preds = %2
store i64 0, i64* %7
br label %19
19: ; preds = %25, %18
%20 = load i64, i64* %7
%21 = icmp slt i64 %20, 65536
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i64, i64* %7
%24 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 %23
store i8 88, i8* %24
br label %25
25: ; preds = %22
%26 = load i64, i64* %7
%27 = add nsw i64 %26, 1
store i64 %27, i64* %7
br label %19
28: ; preds = %19
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_CREAT
%33 = load i32, i32* @O_WRONLY
%34 = or i32 %32, %33
%35 = load i32, i32* @O_SYNC
%36 = or i32 %34, %35
%37 = call i32 @open(i8* %31, i32 %36)
store i32 %37, i32* %9
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i64 @atol(i8* %40)
store i64 %41, i64* %6
%42 = call i32 @ftime(%struct.timeb* %11)
store i64 0, i64* %8
br label %43
43: ; preds = %52, %28
%44 = load i64, i64* %8
%45 = load i64, i64* %6
%46 = mul nsw i64 16, %45
%47 = icmp slt i64 %44, %46
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i32, i32* %9
%50 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%51 = call i32 @write(i32 %49, i8* %50, i32 65536)
br label %52
52: ; preds = %48
%53 = load i64, i64* %8
%54 = add nsw i64 %53, 1
store i64 %54, i64* %8
br label %43
55: ; preds = %43
%56 = call i32 @ftime(%struct.timeb* %12)
%57 = getelementptr inbounds %struct.timeb, %struct.timeb* %12, i32 0, i32 0
%58 = load i32, i32* %57
%59 = getelementptr inbounds %struct.timeb, %struct.timeb* %11, i32 0, i32 0
%60 = load i32, i32* %59
%61 = sub nsw i32 %58, %60
%62 = mul nsw i32 %61, 1000
%63 = getelementptr inbounds %struct.timeb, %struct.timeb* %12, i32 0, i32 1
%64 = load i32, i32* %63
%65 = getelementptr inbounds %struct.timeb, %struct.timeb* %11, i32 0, i32 1
%66 = load i32, i32* %65
%67 = sub nsw i32 %64, %66
%68 = add nsw i32 %62, %67
%69 = sext i32 %68 to i64
store i64 %69, i64* %13
%70 = load i64, i64* %13
%71 = icmp sgt i64 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %55
%73 = load i64, i64* %6
%74 = mul nsw i64 1048576, %73
%75 = load i64, i64* %13
%76 = sdiv i64 %74, %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %76)
br label %78
78: ; preds = %72, %55
%79 = load i32, i32* %9
%80 = call i32 @close(i32 %79)
store i32 0, i32* %3
br label %81
81: ; preds = %78, %16
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
%struct.timeb = type { i32, i32 }
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [37 x i8] c"Bytes per millisecond written = %ld\0A\00"
@str = [55 x i8] c"Arguments are filename to create and size in megabytes\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = alloca %struct.timeb
%5 = alloca %struct.timeb
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.timeb* %4 to i8*
%8 = bitcast %struct.timeb* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_WRONLY
%16 = or i32 %15, %14
%17 = load i32, i32* @O_SYNC
%18 = or i32 %16, %17
%19 = tail call i32 @open(i8* %13, i32 %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i64 @atol(i8* %21)
%23 = call i32 @ftime(%struct.timeb* %4)
%24 = icmp sgt i64 %22, 0
br i1 %24, label %27, label %35
25: ; preds = %2
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %57
27: ; preds = %10
%28 = shl i64 %22, 4
%29 = call i64 @llvm.smax.i64(i64 %28, i64 1)
br label %30
30: ; preds = %27, %30
%31 = phi i64 [ %33, %30 ], [ 0, %27 ]
%32 = call i32 @write(i32 %19, i8* %6, i32 65536)
%33 = add nuw nsw i64 %31, 1
%34 = icmp eq i64 %33, %29
br i1 %34, label %35, label %30
35: ; preds = %30, %10
%36 = call i32 @ftime(%struct.timeb* %5)
%37 = getelementptr inbounds %struct.timeb, %struct.timeb* %5, i64 0, i32 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i64 0, i32 0
%40 = load i32, i32* %39
%41 = sub nsw i32 %38, %40
%42 = mul nsw i32 %41, 1000
%43 = getelementptr inbounds %struct.timeb, %struct.timeb* %5, i64 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i64 0, i32 1
%46 = load i32, i32* %45
%47 = sub nsw i32 %44, %46
%48 = add nsw i32 %47, %42
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %35
%51 = zext i32 %48 to i64
%52 = shl nsw i64 %22, 20
%53 = sdiv i64 %52, %51
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %53)
br label %55
55: ; preds = %50, %35
%56 = call i32 @close(i32 %19)
br label %57
57: ; preds = %55, %25
%58 = phi i32 [ -1, %25 ], [ 0, %55 ]
ret i32 %58
}