#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 timespec {
  int tv_sec;
  int tv_nsec;
};

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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    125c <main+0x12c>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     11b8 <main+0x88>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1263 <main+0x133>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
mov    $0x3a60beb,%edx
call   1050 <expmod@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     120e <main+0xde>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1263 <main+0x133>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
mov    -0x1c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xdf0(%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    $0x40,%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    0x2e8b(%rip),%r15
xor    %ebp,%ebp
cmpl   $0x4,(%r15)
jl     1226 <main+0xf6>
mov    $0x1,%ebx
mov    0x2e8b(%rip),%r12
lea    0xed0(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    11fc <main+0xcc>
mov    $0xd,%edi
mov    %rbx,%rsi
mov    $0x3a60beb,%edx
call   1050 <expmod@plt>
mov    %rax,%r14
mov    (%r12),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    120a <main+0xda>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
sub    0x14(%rsp),%ecx
imul   $0x3b9aca00,%eax,%eax
add    %eax,%ecx
movslq %ecx,%rcx
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
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    1226 <main+0xf6>
mov    $0x1,%ebp
lea    0xdf8(%rip),%rsi
jmp    1216 <main+0xe6>
mov    $0x2,%ebp
lea    0xe05(%rip),%rsi
mov    0x2dbb(%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.timespec = type { i32, i32 }
@LONG_MAX = global i32 0
@CLOCK_MONOTONIC = 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.timespec
%7 = alloca %struct.timespec
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %8
br label %11
11: ; preds = %52, %2
%12 = load i64, i64* %8
%13 = load i32, i32* @LONG_MAX
%14 = sdiv i32 %13, 2
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %12, %15
br i1 %16, label %17, label %55
17: ; preds = %11
%18 = load i32, i32* @CLOCK_MONOTONIC
%19 = call i64 @clock_gettime(i32 %18, %struct.timespec* %6)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%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 %56
24: ; preds = %17
%25 = load i64, i64* %8
%26 = call i64 @expmod(i32 13, i64 %25, i32 61213675)
store i64 %26, i64* %9
%27 = load i32, i32* @CLOCK_MONOTONIC
%28 = call i64 @clock_gettime(i32 %27, %struct.timespec* %7)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %56
33: ; preds = %24
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%37 = load i32, i32* %36
%38 = sub nsw i32 %35, %37
%39 = mul nsw i32 1000000000, %38
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%43 = load i32, i32* %42
%44 = sub nsw i32 %41, %43
%45 = add nsw i32 %39, %44
%46 = sext i32 %45 to i64
store i64 %46, i64* %10
%47 = load i32, i32* @stdout
%48 = load i64, i64* %8
%49 = load i64, i64* %10
%50 = load i64, i64* %9
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %48, i64 %49, i64 %50)
br label %52
52: ; preds = %33
%53 = load i64, i64* %8
%54 = mul nsw i64 %53, 2
store i64 %54, i64* %8
br label %11
55: ; preds = %11
store i32 0, i32* %3
br label %56
56: ; preds = %55, %30, %21
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@LONG_MAX = global i32 0
@CLOCK_MONOTONIC = 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.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = load i32, i32* @LONG_MAX
%8 = icmp sgt i32 %7, 3
br i1 %8, label %9, label %46
9: ; preds = %2
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
br label %14
14: ; preds = %9, %24
%15 = phi i64 [ 1, %9 ], [ %36, %24 ]
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i64 @clock_gettime(i32 %16, %struct.timespec* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %14
%20 = call i64 @expmod(i32 13, i64 %15, i32 61213675)
%21 = load i32, i32* @CLOCK_MONOTONIC
%22 = call i64 @clock_gettime(i32 %21, %struct.timespec* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %19
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = sub nsw i32 %25, %26
%28 = mul nsw i32 %27, 1000000000
%29 = load i32, i32* %12
%30 = load i32, i32* %13
%31 = sub i32 %29, %30
%32 = add nsw i32 %31, %28
%33 = sext i32 %32 to i64
%34 = load i32, i32* @stdout
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %15, i64 %33, i64 %20)
%36 = shl nsw i64 %15, 1
%37 = load i32, i32* @LONG_MAX
%38 = sdiv i32 %37, 2
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %36, %39
br i1 %40, label %14, label %46
41: ; preds = %19, %14
%42 = 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), %19 ]
%43 = phi i32 [ 1, %14 ], [ 2, %19 ]
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* %42)
br label %46
46: ; preds = %24, %41, %2
%47 = phi i32 [ 0, %2 ], [ %43, %41 ], [ 0, %24 ]
ret i32 %47
}