#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__ clock_t;

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ fiolSWriteInt(char *, int);
int /*<<< orphan*/ itoa(int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void benchWriteOneInt(int val1) {
  unsigned int i;
  char msg[255];
  clock_t start, end;
  printf("\t%d\r\n", val1);
  do {
    start = clock();
  } while (0);
  for (i = 0; i < 400000; i++) {
    fiolSWriteInt(msg, val1);
  }
  do {
    end = clock();
    printf("\t\t%s: %f\r\n", "fiolSWriteInt",
           (float)(end - start) / (float)CLOCKS_PER_SEC);
  } while (0);
  do {
    start = clock();
  } while (0);
  for (i = 0; i < 400000; i++) {
    sprintf(msg, "%d", val1);
  }
  do {
    end = clock();
    printf("\t\t%s: %f\r\n", "sscanf",
           (float)(end - start) / (float)CLOCKS_PER_SEC);
  } while (0);
  do {
    start = clock();
  } while (0);
  for (i = 0; i < 400000; i++) {
    itoa(val1, msg, 10);
  }
  do {
    end = clock();
    printf("\t\t%s: %f\r\n", "itoa",
           (float)(end - start) / (float)CLOCKS_PER_SEC);
  } while (0);
  printf("\r\n");
}


x86 assembly (clang, -O0):
<benchWriteOneInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x61a80,-0x8(%rbp)
jae    11ae <benchWriteOneInt+0x5e>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <fiolSWriteInt@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1184 <benchWriteOneInt+0x34>
jmp    11b3 <benchWriteOneInt+0x63>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    -0x118(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2e0d(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe17(%rip),%rdi
lea    0xe1b(%rip),%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1202 <benchWriteOneInt+0xb2>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x61a80,-0x8(%rbp)
jae    1248 <benchWriteOneInt+0xf8>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdea(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1217 <benchWriteOneInt+0xc7>
jmp    124d <benchWriteOneInt+0xfd>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    -0x118(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2d73(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd7d(%rip),%rdi
lea    0xd92(%rip),%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    129c <benchWriteOneInt+0x14c>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x61a80,-0x8(%rbp)
jae    12e0 <benchWriteOneInt+0x190>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xa,%edx
call   1070 <itoa@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12b1 <benchWriteOneInt+0x161>
jmp    12e5 <benchWriteOneInt+0x195>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    -0x118(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2cdb(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xce5(%rip),%rdi
lea    0xd01(%rip),%rsi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchWriteOneInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x61a80,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebx,%esi
call   1060 <fiolSWriteInt@plt>
add    $0xffffffff,%ebp
jne    11a0 <benchWriteOneInt+0x40>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2ss %rax,%xmm0
mov    0x2e23(%rip),%r13
cvtsi2ssq 0x0(%r13),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2c(%rip),%rdi
lea    0xe30(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x61a80,%ebp
lea    0xe21(%rip),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <sprintf@plt>
add    $0xffffffff,%ebp
jne    1210 <benchWriteOneInt+0xb0>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq 0x0(%r13),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdba(%rip),%rdi
lea    0xdcf(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x61a80,%ebp
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1080 <itoa@plt>
add    $0xffffffff,%ebp
jne    1270 <benchWriteOneInt+0x110>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq 0x0(%r13),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd58(%rip),%rdi
lea    0xd74(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd6b(%rip),%rdi
call   1030 <puts@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\09%d\0D\0A\00"
@.str.1 = [11 x i8] c"\09\09%s: %f\0D\0A\00"
@.str.2 = [14 x i8] c"fiolSWriteInt\00"
@CLOCKS_PER_SEC = global i64 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"sscanf\00"
@.str.5 = [5 x i8] c"itoa\00"
@.str.6 = [3 x i8] c"\0D\0A\00"
define void @benchWriteOneInt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %1
%10 = call i64 (...) @clock()
store i64 %10, i64* %5
br label %11
11: ; preds = %9
store i32 0, i32* %3
br label %12
12: ; preds = %19, %11
%13 = load i32, i32* %3
%14 = icmp ult i32 %13, 400000
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %2
%18 = call i32 @fiolSWriteInt(i8* %16, i32 %17)
br label %19
19: ; preds = %15
%20 = load i32, i32* %3
%21 = add i32 %20, 1
store i32 %21, i32* %3
br label %12
22: ; preds = %12
br label %23
23: ; preds = %22
%24 = call i64 (...) @clock()
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = load i64, i64* %5
%27 = sub nsw i64 %25, %26
%28 = sitofp i64 %27 to float
%29 = load i64, i64* @CLOCKS_PER_SEC
%30 = sitofp i64 %29 to float
%31 = fdiv float %28, %30
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %34
34: ; preds = %23
br label %35
35: ; preds = %34
%36 = call i64 (...) @clock()
store i64 %36, i64* %5
br label %37
37: ; preds = %35
store i32 0, i32* %3
br label %38
38: ; preds = %45, %37
%39 = load i32, i32* %3
%40 = icmp ult i32 %39, 400000
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%43 = load i32, i32* %2
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41
%46 = load i32, i32* %3
%47 = add i32 %46, 1
store i32 %47, i32* %3
br label %38
48: ; preds = %38
br label %49
49: ; preds = %48
%50 = call i64 (...) @clock()
store i64 %50, i64* %6
%51 = load i64, i64* %6
%52 = load i64, i64* %5
%53 = sub nsw i64 %51, %52
%54 = sitofp i64 %53 to float
%55 = load i64, i64* @CLOCKS_PER_SEC
%56 = sitofp i64 %55 to float
%57 = fdiv float %54, %56
%58 = fpext float %57 to double
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %58)
br label %60
60: ; preds = %49
br label %61
61: ; preds = %60
%62 = call i64 (...) @clock()
store i64 %62, i64* %5
br label %63
63: ; preds = %61
store i32 0, i32* %3
br label %64
64: ; preds = %71, %63
%65 = load i32, i32* %3
%66 = icmp ult i32 %65, 400000
br i1 %66, label %67, label %74
67: ; preds = %64
%68 = load i32, i32* %2
%69 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%70 = call i32 @itoa(i32 %68, i8* %69, i32 10)
br label %71
71: ; preds = %67
%72 = load i32, i32* %3
%73 = add i32 %72, 1
store i32 %73, i32* %3
br label %64
74: ; preds = %64
br label %75
75: ; preds = %74
%76 = call i64 (...) @clock()
store i64 %76, i64* %6
%77 = load i64, i64* %6
%78 = load i64, i64* %5
%79 = sub nsw i64 %77, %78
%80 = sitofp i64 %79 to float
%81 = load i64, i64* @CLOCKS_PER_SEC
%82 = sitofp i64 %81 to float
%83 = fdiv float %80, %82
%84 = fpext float %83 to double
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %84)
br label %86
86: ; preds = %75
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\09%d\0D\0A\00"
@.str.1 = [11 x i8] c"\09\09%s: %f\0D\0A\00"
@.str.2 = [14 x i8] c"fiolSWriteInt\00"
@CLOCKS_PER_SEC = global i64 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"sscanf\00"
@.str.5 = [5 x i8] c"itoa\00"
@str = [2 x i8] c"\0D\00"
define void @benchWriteOneInt(i32 %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = tail call i64 (...) @clock()
br label %6
6: ; preds = %1, %6
%7 = phi i32 [ 0, %1 ], [ %9, %6 ]
%8 = call i32 @fiolSWriteInt(i8* %3, i32 %0)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %9, 400000
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = call i64 (...) @clock()
%13 = sub nsw i64 %12, %5
%14 = sitofp i64 %13 to float
%15 = load i64, i64* @CLOCKS_PER_SEC
%16 = sitofp i64 %15 to float
%17 = fdiv float %14, %16
%18 = fpext float %17 to double
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = call i64 (...) @clock()
br label %21
21: ; preds = %11, %21
%22 = phi i32 [ 0, %11 ], [ %24, %21 ]
%23 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, 400000
br i1 %25, label %26, label %21
26: ; preds = %21
%27 = call i64 (...) @clock()
%28 = sub nsw i64 %27, %20
%29 = sitofp i64 %28 to float
%30 = load i64, i64* @CLOCKS_PER_SEC
%31 = sitofp i64 %30 to float
%32 = fdiv float %29, %31
%33 = fpext float %32 to double
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %33)
%35 = call i64 (...) @clock()
br label %36
36: ; preds = %26, %36
%37 = phi i32 [ 0, %26 ], [ %39, %36 ]
%38 = call i32 @itoa(i32 %0, i8* %3, i32 10)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, 400000
br i1 %40, label %41, label %36
41: ; preds = %36
%42 = call i64 (...) @clock()
%43 = sub nsw i64 %42, %35
%44 = sitofp i64 %43 to float
%45 = load i64, i64* @CLOCKS_PER_SEC
%46 = sitofp i64 %45 to float
%47 = fdiv float %44, %46
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %48)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}