#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 int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ calculate_add_time(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ calculate_mul_time(int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int iterations = 10;
  if (argc >= 2) {
    iterations = atoi(argv[1]);
  }
  uint64_t *values = (uint64_t *)malloc(iterations * sizeof(uint64_t));
  if (argc >= 3 && strcmp(argv[2], "add")) {
    calculate_add_time(iterations, values);
  } else {
    calculate_mul_time(iterations, values);
  }
  for (int i = 0; i < iterations; i++) {
    printf("%lu\n", values[i]);
  }
  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)
movl   $0xa,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11e3 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11e3 <main+0x83>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <calculate_add_time@plt>
jmp    11ef <main+0x8f>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <calculate_mul_time@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1227 <main+0xc7>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f6 <main+0x96>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jle    11ba <main+0x5a>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%ebp
je     11cd <main+0x6d>
mov    0x10(%r15),%rdi
lea    0xe62(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11cd <main+0x6d>
mov    %r14d,%edi
mov    %r12,%rsi
call   1040 <calculate_add_time@plt>
test   %r14d,%r14d
jg     11dd <main+0x7d>
jmp    1205 <main+0xa5>
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0xa,%r14d
mov    %r14d,%edi
mov    %r12,%rsi
call   1070 <calculate_mul_time@plt>
test   %r14d,%r14d
jle    1205 <main+0xa5>
mov    %r14d,%ebx
xor    %ebp,%ebp
lea    0xe1b(%rip),%r14
nopl   0x0(%rax)
mov    (%r12,%rbp,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11f0 <main+0x90>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"add\00"
@.str.1 = [5 x i8] c"%lu\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %11, %2
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %7
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 3
br i1 %24, label %25, label %35
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* %6
%33 = load i32*, i32** %7
%34 = call i32 @calculate_add_time(i32 %32, i32* %33)
br label %39
35: ; preds = %25, %16
%36 = load i32, i32* %6
%37 = load i32*, i32** %7
%38 = call i32 @calculate_mul_time(i32 %36, i32* %37)
br label %39
39: ; preds = %35, %31
store i32 0, i32* %8
br label %40
40: ; preds = %51, %39
%41 = load i32, i32* %8
%42 = load i32, i32* %6
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i32*, i32** %7
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %40
54: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"add\00"
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i64 @malloc(i32 40)
%6 = inttoptr i64 %5 to i32*
br label %22
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = icmp eq i32 %0, 2
br i1 %14, label %22, label %15
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = tail call i32 @calculate_add_time(i32 %10, i32* %13)
br label %26
22: ; preds = %4, %15, %7
%23 = phi i32* [ %6, %4 ], [ %13, %15 ], [ %13, %7 ]
%24 = phi i32 [ 10, %4 ], [ %10, %15 ], [ %10, %7 ]
%25 = tail call i32 @calculate_mul_time(i32 %24, i32* %23)
br label %26
26: ; preds = %22, %20
%27 = phi i32* [ %23, %22 ], [ %13, %20 ]
%28 = phi i32 [ %24, %22 ], [ %10, %20 ]
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = zext i32 %28 to i64
br label %33
32: ; preds = %33, %26
ret i32 0
33: ; preds = %30, %33
%34 = phi i64 [ 0, %30 ], [ %38, %33 ]
%35 = getelementptr inbounds i32, i32* %27, i64 %34
%36 = load i32, i32* %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i64 %34, 1
%39 = icmp eq i64 %38, %31
br i1 %39, label %32, label %33
}