#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 */
double benchmark(int, int);
int pow(int, int);
int /*<<< orphan*/ print_results(int, double);
int /*<<< orphan*/ print_summary(int, int);
int /*<<< orphan*/ print_version();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  double elapsed;
  int count;
  int iter;
  int len;
  int i;
  int j;
  srand(time(NULL));
  print_version();
  count = 0;
  for (i = 1; i <= 6; i++) {
    len = pow(10, i);
    iter = 1000000 / pow(10, i - 1);
    for (j = 0; j < 3; j++) {
      count += 1;
      printf("# c::%s:len=%d\n", "dcusumpw", len);
      elapsed = benchmark(iter, len);
      print_results(iter, elapsed);
      printf("ok %d benchmark finished\n", count);
    }
  }
  print_summary(count, count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   1030 <print_version@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
jg     126c <main+0xec>
mov    -0x20(%rbp),%esi
mov    $0xa,%edi
call   1090 <pow@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1090 <pow@plt>
mov    %eax,%ecx
mov    $0xf4240,%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1259 <main+0xd9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edx
lea    0xdf1(%rip),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <benchmark@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
call   1050 <print_results@plt>
mov    -0x14(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f2 <main+0x72>
jmp    125e <main+0xde>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <main+0x34>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10a0 <print_summary@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1030 <print_version@plt>
mov    $0x1,%r14d
mov    $0x3,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %r14d,%esi
call   1090 <pow@plt>
mov    %eax,%ebp
lea    -0x1(%r14),%esi
mov    $0xa,%edi
call   1090 <pow@plt>
mov    %eax,%ecx
mov    $0xf4240,%eax
xor    %edx,%edx
idiv   %ecx
mov    %eax,%r15d
lea    -0x2(%rbx),%r12d
lea    0xe1a(%rip),%rdi
lea    0xe23(%rip),%r13
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1080 <benchmark@plt>
mov    %r15d,%edi
call   1050 <print_results@plt>
lea    0xe07(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%rbx),%r12d
lea    0xdd9(%rip),%rdi
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1080 <benchmark@plt>
mov    %r15d,%edi
call   1050 <print_results@plt>
lea    0xdcd(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xda3(%rip),%rdi
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1080 <benchmark@plt>
mov    %r15d,%edi
call   1050 <print_results@plt>
lea    0xd97(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x3,%ebx
add    $0x1,%r14d
cmp    $0x7,%r14d
jne    11b0 <main+0x30>
mov    $0x12,%edi
mov    $0x12,%esi
call   10a0 <print_summary@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"# c::%s:len=%d\0A\00"
@.str.1 = [9 x i8] c"dcusumpw\00"
@.str.2 = [26 x i8] c"ok %d benchmark finished\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @print_version()
store i32 0, i32* %3
store i32 1, i32* %6
br label %11
11: ; preds = %41, %0
%12 = load i32, i32* %6
%13 = icmp sle i32 %12, 6
br i1 %13, label %14, label %44
14: ; preds = %11
%15 = load i32, i32* %6
%16 = call i32 @pow(i32 10, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = call i32 @pow(i32 10, i32 %18)
%20 = sdiv i32 1000000, %19
store i32 %20, i32* %4
store i32 0, i32* %7
br label %21
21: ; preds = %37, %14
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %40
24: ; preds = %21
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call double @benchmark(i32 %29, i32 %30)
store double %31, double* %2
%32 = load i32, i32* %4
%33 = load double, double* %2
%34 = call i32 @print_results(i32 %32, double %33)
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %21
40: ; preds = %21
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %11
44: ; preds = %11
%45 = load i32, i32* %3
%46 = load i32, i32* %3
%47 = call i32 @print_summary(i32 %45, i32 %46)
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [16 x i8] c"# c::%s:len=%d\0A\00"
@.str.1 = [9 x i8] c"dcusumpw\00"
@.str.2 = [26 x i8] c"ok %d benchmark finished\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @print_version()
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 1, %0 ], [ %26, %4 ]
%6 = phi i32 [ 0, %0 ], [ %21, %4 ]
%7 = tail call i32 @pow(i32 10, i32 %5)
%8 = add nsw i32 %5, -1
%9 = tail call i32 @pow(i32 10, i32 %8)
%10 = sdiv i32 1000000, %9
%11 = add nuw nsw i32 %6, 1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%13 = tail call double @benchmark(i32 %10, i32 %7)
%14 = tail call i32 @print_results(i32 %10, double %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%16 = add nuw nsw i32 %6, 2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%18 = tail call double @benchmark(i32 %10, i32 %7)
%19 = tail call i32 @print_results(i32 %10, double %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%21 = add nuw nsw i32 %6, 3
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%23 = tail call double @benchmark(i32 %10, i32 %7)
%24 = tail call i32 @print_results(i32 %10, double %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%26 = add nuw nsw i32 %5, 1
%27 = icmp eq i32 %26, 7
br i1 %27, label %28, label %4
28: ; preds = %4
%29 = tail call i32 @print_summary(i32 18, i32 18)
ret i32 0
}