#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 timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int LONG_MAX;
long expmod(int, long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  struct timeval start;
  struct timeval finish;
  for (long expt = 1; expt < LONG_MAX / 2; expt *= 2) {
    if (gettimeofday(&start, NULL)) {
      fprintf(stderr, "Could not get start time.\n");
      return 1;
    }
    long result;
    for (int i = 0; i < 100; i++) {
      result = expmod(13, expt, 612131675);
    }
    if (gettimeofday(&finish, NULL)) {
      fprintf(stderr, "Could not get end time.\n");
      return 2;
    }
    long elapsed = 1000000 * (finish.tv_sec - start.tv_sec) +
                   (finish.tv_usec - start.tv_usec);
    fprintf(stdout, "%ld,%ld,%ld\n", expt, elapsed, result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    1271 <main+0x141>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     11b3 <main+0x83>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <main+0x148>
movl   $0x0,-0x34(%rbp)
cmpl   $0x64,-0x34(%rbp)
jge    11e9 <main+0xb9>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
mov    $0x247c635b,%edx
call   1050 <expmod@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <main+0x8a>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     1223 <main+0xf3>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1278 <main+0x148>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0xf4240,%eax,%eax
mov    -0x1c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x40(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114e <main+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e93(%rip),%r15
xor    %ebp,%ebp
cmpl   $0x4,(%r15)
jl     1236 <main+0x106>
mov    $0x1,%ebx
lea    0x8(%rsp),%r12
lea    0xed2(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    120c <main+0xdc>
mov    $0x64,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0xd,%edi
mov    %rbx,%rsi
mov    $0x247c635b,%edx
call   1050 <expmod@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x60>
mov    %rax,%r14
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    121a <main+0xea>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
sub    0x14(%rsp),%ecx
imul   $0xf4240,%eax,%eax
add    %eax,%ecx
movslq %ecx,%rcx
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
add    %rbx,%rbx
mov    (%r15),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
cmp    %rax,%rbx
jl     1170 <main+0x40>
jmp    1236 <main+0x106>
mov    $0x1,%ebp
lea    0xde8(%rip),%rsi
jmp    1226 <main+0xf6>
mov    $0x2,%ebp
lea    0xdf5(%rip),%rsi
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@LONG_MAX = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Could not get start time.\0A\00"
@.str.1 = [25 x i8] c"Could not get end time.\0A\00"
@stdout = global i32 0
@.str.2 = [13 x i8] c"%ld,%ld,%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %8
br label %12
12: ; preds = %59, %2
%13 = load i64, i64* %8
%14 = load i32, i32* @LONG_MAX
%15 = sdiv i32 %14, 2
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %13, %16
br i1 %17, label %18, label %62
18: ; preds = %12
%19 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %63
24: ; preds = %18
store i32 0, i32* %10
br label %25
25: ; preds = %31, %24
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 100
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i64, i64* %8
%30 = call i64 @expmod(i32 13, i64 %29, i32 612131675)
store i64 %30, i64* %9
br label %31
31: ; preds = %28
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %25
34: ; preds = %25
%35 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %63
40: ; preds = %34
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sub nsw i32 %42, %44
%46 = mul nsw i32 1000000, %45
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%50 = load i32, i32* %49
%51 = sub nsw i32 %48, %50
%52 = add nsw i32 %46, %51
%53 = sext i32 %52 to i64
store i64 %53, i64* %11
%54 = load i32, i32* @stdout
%55 = load i64, i64* %8
%56 = load i64, i64* %11
%57 = load i64, i64* %9
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %55, i64 %56, i64 %57)
br label %59
59: ; preds = %40
%60 = load i64, i64* %8
%61 = mul nsw i64 %60, 2
store i64 %61, i64* %8
br label %12
62: ; preds = %12
store i32 0, i32* %3
br label %63
63: ; preds = %62, %37, %21
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@LONG_MAX = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Could not get start time.\0A\00"
@.str.1 = [25 x i8] c"Could not get end time.\0A\00"
@stdout = global i32 0
@.str.2 = [13 x i8] c"%ld,%ld,%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = load i32, i32* @LONG_MAX
%8 = icmp sgt i32 %7, 3
br i1 %8, label %9, label %48
9: ; preds = %2
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %14
14: ; preds = %9, %26
%15 = phi i64 [ 1, %9 ], [ %38, %26 ]
%16 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %43
18: ; preds = %21
%19 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %43
21: ; preds = %14, %21
%22 = phi i32 [ %24, %21 ], [ 0, %14 ]
%23 = tail call i64 @expmod(i32 13, i64 %15, i32 612131675)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, 100
br i1 %25, label %18, label %21
26: ; preds = %18
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = sub nsw i32 %27, %28
%30 = mul nsw i32 %29, 1000000
%31 = load i32, i32* %12
%32 = load i32, i32* %13
%33 = sub i32 %31, %32
%34 = add nsw i32 %33, %30
%35 = sext i32 %34 to i64
%36 = load i32, i32* @stdout
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %15, i64 %35, i64 %23)
%38 = shl nsw i64 %15, 1
%39 = load i32, i32* @LONG_MAX
%40 = sdiv i32 %39, 2
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %38, %41
br i1 %42, label %14, label %48
43: ; preds = %18, %14
%44 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %14 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %18 ]
%45 = phi i32 [ 1, %14 ], [ 2, %18 ]
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* %44)
br label %48
48: ; preds = %26, %43, %2
%49 = phi i32 [ 0, %2 ], [ %45, %43 ], [ 0, %26 ]
ret i32 %49
}