#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 */
int /*<<< orphan*/ expmod(long, long, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int rand();
int /*<<< orphan*/ sr_check_long(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                                 long);
scalar_t__ sr_get_errors();
int /*<<< orphan*/ sr_report(int /*<<< orphan*/);
int /*<<< orphan*/ sr_reset();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  sr_reset();
  srand(time(0));
  long val;
  long mod;
  long maxExp;
  for (int i = 0; i < 100; i++) {
    fprintf(stderr, "Running test %d\n", i);
    val = rand();
    mod = rand();
    maxExp = rand() % 10000;
    val %= mod;
    sr_check_long(stderr, "expmod(val, 0, mod)", expmod(val, 0, mod), 1);
    ;
    sr_check_long(stderr, "expmod(val, 1, mod)", expmod(val, 1, mod), val);
    ;
    long current = val;
    for (long e = 2; e <= maxExp; e++) {
      current = (current * val) % mod;
      sr_check_long(stderr, "expmod(val, e, mod)", expmod(val, e, mod),
                    current);
      ;
    }
  }
  if (sr_get_errors()) {
    sr_report(stderr);
    return 1;
  } else {
    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)
mov    $0x0,%al
call   1040 <sr_reset@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x64,-0x2c(%rbp)
jge    1312 <main+0x182>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe21(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <expmod@plt>
mov    -0x48(%rbp),%edi
mov    %eax,%edx
lea    0xdc3(%rip),%rsi
mov    $0x1,%ecx
call   1030 <sr_check_long@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1,%esi
call   1090 <expmod@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xd9f(%rip),%rsi
call   1030 <sr_check_long@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x2,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jg     12ff <main+0x16f>
mov    -0x38(%rbp),%rax
imul   -0x18(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,-0x38(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <expmod@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
lea    0xd50(%rip),%rsi
call   1030 <sr_check_long@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    129b <main+0x10b>
jmp    1304 <main+0x174>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c2 <main+0x32>
mov    $0x0,%al
call   10a0 <sr_get_errors@plt>
cmp    $0x0,%rax
je     133d <main+0x1ad>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   1060 <sr_report@plt>
movl   $0x1,-0x4(%rbp)
jmp    1344 <main+0x1b4>
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
push   %rax
xor    %eax,%eax
call   1040 <sr_reset@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %ebp,%ebp
jmp    11cf <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%ebp
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1330 <main+0x1a0>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%r15d
movslq %eax,%r12
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%r13d
movslq %eax,%r14
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x68db8bad,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
imul   $0x2710,%eax,%eax
sub    %eax,%ebx
mov    %r12,%rax
or     %r14,%rax
shr    $0x20,%rax
mov    %ebp,(%rsp)
mov    %r13d,0x4(%rsp)
je     1250 <main+0xc0>
mov    %r12,%rax
cqto
idiv   %r14
mov    %rdx,%r13
jmp    125b <main+0xcb>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
xor    %edx,%edx
div    %r13d
mov    %edx,%r13d
mov    0x2d7e(%rip),%r15
mov    (%r15),%ebp
mov    %r13,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1090 <expmod@plt>
mov    $0x1,%ecx
mov    %ebp,%edi
lea    0xd91(%rip),%rsi
mov    %eax,%edx
call   1030 <sr_check_long@plt>
mov    (%r15),%ebp
mov    $0x1,%esi
mov    %r13,%rdi
mov    %r14,%rdx
call   1090 <expmod@plt>
mov    %ebp,%edi
lea    0xd82(%rip),%rsi
mov    %eax,%edx
mov    %r13,%rcx
call   1030 <sr_check_long@plt>
cmp    $0x2,%ebx
jl     11c0 <main+0x30>
add    $0x1,%ebx
mov    $0x2,%r12d
mov    %r13,%r15
jmp    1312 <main+0x182>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rax
cqto
idiv   %r14
mov    %rdx,%r15
mov    0x2cfe(%rip),%rax
mov    (%rax),%ebp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <expmod@plt>
mov    %ebp,%edi
lea    0xd3e(%rip),%rsi
mov    %eax,%edx
mov    %r15,%rcx
call   1030 <sr_check_long@plt>
add    $0x1,%r12
cmp    %r12,%rbx
je     11c0 <main+0x30>
imul   %r13,%r15
mov    %r15,%rax
or     %r14,%rax
shr    $0x20,%rax
jne    12d0 <main+0x140>
mov    %r15d,%eax
xor    %edx,%edx
divl   0x4(%rsp)
mov    %edx,%r15d
jmp    12db <main+0x14b>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <sr_get_errors@plt>
test   %rax,%rax
je     1351 <main+0x1c1>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1060 <sr_report@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Running test %d\0A\00"
@.str.1 = [20 x i8] c"expmod(val, 0, mod)\00"
@.str.2 = [20 x i8] c"expmod(val, 1, mod)\00"
@.str.3 = [20 x i8] c"expmod(val, e, mod)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @sr_reset()
%13 = call i32 @time(i32 0)
%14 = call i32 @srand(i32 %13)
store i32 0, i32* %9
br label %15
15: ; preds = %65, %2
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 100
br i1 %17, label %18, label %68
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i32, i32* %9
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @rand()
%23 = sext i32 %22 to i64
store i64 %23, i64* %6
%24 = call i32 (...) @rand()
%25 = sext i32 %24 to i64
store i64 %25, i64* %7
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10000
%28 = sext i32 %27 to i64
store i64 %28, i64* %8
%29 = load i64, i64* %7
%30 = load i64, i64* %6
%31 = srem i64 %30, %29
store i64 %31, i64* %6
%32 = load i32, i32* @stderr
%33 = load i64, i64* %6
%34 = load i64, i64* %7
%35 = call i32 @expmod(i64 %33, i64 0, i64 %34)
%36 = call i32 @sr_check_long(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %35, i64 1)
%37 = load i32, i32* @stderr
%38 = load i64, i64* %6
%39 = load i64, i64* %7
%40 = call i32 @expmod(i64 %38, i64 1, i64 %39)
%41 = load i64, i64* %6
%42 = call i32 @sr_check_long(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %40, i64 %41)
%43 = load i64, i64* %6
store i64 %43, i64* %10
store i64 2, i64* %11
br label %44
44: ; preds = %61, %18
%45 = load i64, i64* %11
%46 = load i64, i64* %8
%47 = icmp sle i64 %45, %46
br i1 %47, label %48, label %64
48: ; preds = %44
%49 = load i64, i64* %10
%50 = load i64, i64* %6
%51 = mul nsw i64 %49, %50
%52 = load i64, i64* %7
%53 = srem i64 %51, %52
store i64 %53, i64* %10
%54 = load i32, i32* @stderr
%55 = load i64, i64* %6
%56 = load i64, i64* %11
%57 = load i64, i64* %7
%58 = call i32 @expmod(i64 %55, i64 %56, i64 %57)
%59 = load i64, i64* %10
%60 = call i32 @sr_check_long(i32 %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %58, i64 %59)
br label %61
61: ; preds = %48
%62 = load i64, i64* %11
%63 = add nsw i64 %62, 1
store i64 %63, i64* %11
br label %44
64: ; preds = %44
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %15
68: ; preds = %15
%69 = call i64 (...) @sr_get_errors()
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32, i32* @stderr
%73 = call i32 @sr_report(i32 %72)
store i32 1, i32* %3
br label %75
74: ; preds = %68
store i32 0, i32* %3
br label %75
75: ; preds = %74, %71
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Running test %d\0A\00"
@.str.1 = [20 x i8] c"expmod(val, 0, mod)\00"
@.str.2 = [20 x i8] c"expmod(val, 1, mod)\00"
@.str.3 = [20 x i8] c"expmod(val, e, mod)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @sr_reset()
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
br label %9
6: ; preds = %30
%7 = tail call i64 (...) @sr_get_errors()
%8 = icmp eq i64 %7, 0
br i1 %8, label %46, label %43
9: ; preds = %2, %30
%10 = phi i32 [ 0, %2 ], [ %31, %30 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = tail call i32 (...) @rand()
%14 = sext i32 %13 to i64
%15 = tail call i32 (...) @rand()
%16 = sext i32 %15 to i64
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 10000
%19 = srem i64 %14, %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @expmod(i64 %19, i64 0, i64 %16)
%22 = tail call i32 @sr_check_long(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %21, i64 1)
%23 = load i32, i32* @stderr
%24 = tail call i32 @expmod(i64 %19, i64 1, i64 %16)
%25 = tail call i32 @sr_check_long(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %24, i64 %19)
%26 = icmp slt i32 %18, 2
br i1 %26, label %30, label %27
27: ; preds = %9
%28 = add nuw nsw i32 %18, 1
%29 = zext i32 %28 to i64
br label %33
30: ; preds = %33, %9
%31 = add nuw nsw i32 %10, 1
%32 = icmp eq i32 %31, 100
br i1 %32, label %6, label %9
33: ; preds = %27, %33
%34 = phi i64 [ %41, %33 ], [ 2, %27 ]
%35 = phi i64 [ %37, %33 ], [ %19, %27 ]
%36 = mul nsw i64 %35, %19
%37 = srem i64 %36, %16
%38 = load i32, i32* @stderr
%39 = tail call i32 @expmod(i64 %19, i64 %34, i64 %16)
%40 = tail call i32 @sr_check_long(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %39, i64 %37)
%41 = add nuw nsw i64 %34, 1
%42 = icmp eq i64 %41, %29
br i1 %42, label %30, label %33
43: ; preds = %6
%44 = load i32, i32* @stderr
%45 = tail call i32 @sr_report(i32 %44)
br label %46
46: ; preds = %6, %43
%47 = phi i32 [ 1, %43 ], [ 0, %6 ]
ret i32 %47
}