#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*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  FILE *file = fopen("resources/p099_base_exp.txt", "r");
  mpz_t current;
  mpz_init(current);
  mpz_t max;
  mpz_init(max);
  int max_index = 1;
  char line[128];
  for (int current_index = 1; fgets(line, sizeof line, file); ++current_index) {
    char *c = line;
    for (; *c != ','; ++c)
      ;
    *c = 0;
    mpz_set_str(current, line, 10);
    mpz_pow_ui(current, current, atoi(c + 1));
    if (mpz_cmp(current, max) > 0) {
      mpz_set(max, current);
      max_index = current_index;
    }
    current_index++;
  }
  fclose(file);
  printf("%d\n", max_index);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpz_init@plt>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0xb4(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ec <main+0x14c>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     124d <main+0xad>
jmp    1236 <main+0x96>
mov    -0xc0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc0(%rbp)
jmp    121e <main+0x7e>
mov    -0xc0(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0xa,%edx
call   1080 <mpz_set_str@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc8(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc0(%rbp),%rdi
add    $0x1,%rdi
call   10c0 <atoi@plt>
mov    -0xc8(%rbp),%edi
mov    -0xc4(%rbp),%esi
mov    %eax,%edx
call   1090 <mpz_pow_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10a0 <mpz_cmp@plt>
cmp    $0x0,%rax
jle    12c9 <main+0x129>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11f1 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xd1f(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xe4a(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     125d <main+0xbd>
mov    $0x1,%ebp
mov    $0x1,%r15d
jmp    1218 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x2,%ebp
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1263 <main+0xc3>
mov    %r12,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x2c,(%rbx)
lea    0x1(%rbx),%rbx
jne    1220 <main+0x80>
movb   $0x0,-0x1(%rbx)
mov    %r12,%rsi
mov    $0xa,%edx
call   1080 <mpz_set_str@plt>
mov    %rbx,%rdi
call   10c0 <atoi@plt>
mov    %eax,%edx
call   1090 <mpz_pow_ui@plt>
call   10a0 <mpz_cmp@plt>
test   %rax,%rax
jle    1200 <main+0x60>
call   1030 <mpz_set@plt>
mov    %ebp,%r15d
jmp    1200 <main+0x60>
mov    $0x1,%r15d
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xdac(%rip),%rdi
mov    %r15d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"resources/p099_base_exp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%d\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
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32, i32* %7
%15 = call i32 @mpz_init(i32 %14)
%16 = load i32, i32* %8
%17 = call i32 @mpz_init(i32 %16)
store i32 1, i32* %9
store i32 1, i32* %11
br label %18
18: ; preds = %57, %2
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i64 @fgets(i8* %19, i32 128, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %60
23: ; preds = %18
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8* %24, i8** %12
br label %25
25: ; preds = %31, %23
%26 = load i8*, i8** %12
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 44
br i1 %29, label %30, label %34
30: ; preds = %25
br label %31
31: ; preds = %30
%32 = load i8*, i8** %12
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %12
br label %25
34: ; preds = %25
%35 = load i8*, i8** %12
store i8 0, i8* %35
%36 = load i32, i32* %7
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%38 = call i32 @mpz_set_str(i32 %36, i8* %37, i32 10)
%39 = load i32, i32* %7
%40 = load i32, i32* %7
%41 = load i8*, i8** %12
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i32 @atoi(i8* %42)
%44 = call i32 @mpz_pow_ui(i32 %39, i32 %40, i32 %43)
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = call i64 @mpz_cmp(i32 %45, i32 %46)
%48 = icmp sgt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %34
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = call i32 @mpz_set(i32 %50, i32 %51)
%53 = load i32, i32* %11
store i32 %53, i32* %9
br label %54
54: ; preds = %49, %34
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %57
57: ; preds = %54
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %18
60: ; preds = %18
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32, i32* %9
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"resources/p099_base_exp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = call i64 @fgets(i8* %7, i32 128, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2, %30
%11 = phi i32 [ %32, %30 ], [ 1, %2 ]
%12 = phi i32 [ %31, %30 ], [ 1, %2 ]
br label %17
13: ; preds = %30, %2
%14 = phi i32 [ 1, %2 ], [ %31, %30 ]
%15 = call i32 @fclose(i32* %4)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret i32 0
17: ; preds = %17, %10
%18 = phi i8* [ %21, %17 ], [ %7, %10 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 44
%21 = getelementptr inbounds i8, i8* %18, i64 1
br i1 %20, label %22, label %17
22: ; preds = %17
store i8 0, i8* %18
%23 = call i32 @mpz_set_str(i32 undef, i8* %7, i32 10)
%24 = call i32 @atoi(i8* %21)
%25 = call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %24)
%26 = call i64 @mpz_cmp(i32 undef, i32 undef)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @mpz_set(i32 undef, i32 undef)
br label %30
30: ; preds = %28, %22
%31 = phi i32 [ %11, %28 ], [ %12, %22 ]
%32 = add nuw nsw i32 %11, 2
%33 = call i64 @fgets(i8* %7, i32 128, i32* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %13, label %10
}