#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 benchtime {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
struct benchtime *bench_begin();
int /*<<< orphan*/ bench_done(struct benchtime *);
double compute(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("usage: sumsq COUNT REPEATS\n");
    exit(1);
  }
  int count = atoi(argv[1]);
  assert(count >= 1);
  int repeats = atoi(argv[2]);
  assert(repeats >= 1);
  struct benchtime *bt = bench_begin();
  double result = 0;
  for (int i = 0; i < repeats; i++) {
    result = compute(count);
  }
  bench_done(bt);
  printf("result = %g\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1090 <bench_begin@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    122b <main+0xbb>
mov    -0x14(%rbp),%edi
call   1080 <compute@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1204 <main+0x94>
mov    -0x20(%rbp),%rdi
call   1030 <bench_done@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    121e <main+0x9e>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
xor    %eax,%eax
call   10a0 <bench_begin@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11ee <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1090 <compute@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x60>
jmp    11f1 <main+0x71>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1030 <bench_done@plt>
lea    0xdfa(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.benchtime = type { i32 }
@.str = [28 x i8] c"usage: sumsq COUNT REPEATS\0A\00"
@.str.1 = [13 x i8] c"result = %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.benchtime*
%9 = alloca double
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp sge i32 %29, 1
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call %struct.benchtime* (...) @bench_begin()
store %struct.benchtime* %33, %struct.benchtime** %8
store double 0.000000e+00, double* %9
store i32 0, i32* %10
br label %34
34: ; preds = %41, %16
%35 = load i32, i32* %10
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* %6
%40 = call double @compute(i32 %39)
store double %40, double* %9
br label %41
41: ; preds = %38
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %34
44: ; preds = %34
%45 = load %struct.benchtime*, %struct.benchtime** %8
%46 = call i32 @bench_done(%struct.benchtime* %45)
%47 = load double, double* %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %47)
ret i32 0
}

LLVM IR (-O2):
%struct.benchtime = type { i32 }
@.str.1 = [13 x i8] c"result = %g\0A\00"
@str = [27 x i8] c"usage: sumsq COUNT REPEATS\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = tail call %struct.benchtime* (...) @bench_begin()
br i1 %17, label %25, label %21
21: ; preds = %25, %7
%22 = phi double [ 0.000000e+00, %7 ], [ %27, %25 ]
%23 = tail call i32 @bench_done(%struct.benchtime* %20)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %22)
ret i32 0
25: ; preds = %7, %25
%26 = phi i32 [ %28, %25 ], [ 0, %7 ]
%27 = tail call double @compute(i32 %10)
%28 = add nuw nsw i32 %26, 1
%29 = icmp eq i32 %28, %16
br i1 %29, label %21, label %25
}