#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 NumberOfOperations(long long);
int GetOperation(long long i, long long index) {
  if (index < NumberOfOperations(i) - 2)
    return 3 + index + i * NumberOfOperations(0);
  else if (index == NumberOfOperations(i) - 2)
    return i + 1;
  else if (index == NumberOfOperations(i) - 1)
    return 2 - i;
}


x86 assembly (clang, -O0):
<GetOperation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <NumberOfOperations@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    117f <GetOperation+0x6f>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <NumberOfOperations@plt>
mov    -0x30(%rbp),%rcx
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq %edx,%rdx
imul   %rdx,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    11f6 <GetOperation+0xe6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <NumberOfOperations@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jne    11b5 <GetOperation+0xa5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    11f6 <GetOperation+0xe6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <NumberOfOperations@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jne    11ec <GetOperation+0xdc>
mov    $0x2,%eax
sub    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11f6 <GetOperation+0xe6>
jmp    11f1 <GetOperation+0xe1>
jmp    11f6 <GetOperation+0xe6>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetOperation>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <NumberOfOperations@plt>
add    $0xfffffffe,%eax
cltq
cmp    %r14,%rax
jle    113b <GetOperation+0x2b>
xor    %edi,%edi
call   1030 <NumberOfOperations@plt>
imul   %eax,%ebx
add    %r14d,%ebx
add    $0x3,%ebx
jmp    116d <GetOperation+0x5d>
mov    %rbx,%rdi
call   1030 <NumberOfOperations@plt>
add    $0xfffffffe,%eax
cltq
cmp    %r14,%rax
jne    1152 <GetOperation+0x42>
add    $0x1,%ebx
jmp    116d <GetOperation+0x5d>
mov    %rbx,%rdi
call   1030 <NumberOfOperations@plt>
add    $0xffffffff,%eax
cltq
cmp    %r14,%rax
jne    116d <GetOperation+0x5d>
mov    $0x2,%eax
sub    %ebx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @GetOperation(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %5
%7 = load i64, i64* %4
%8 = call i32 @NumberOfOperations(i64 %7)
%9 = sub nsw i32 %8, 2
%10 = sext i32 %9 to i64
%11 = icmp slt i64 %6, %10
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i64, i64* %5
%14 = add nsw i64 3, %13
%15 = load i64, i64* %4
%16 = call i32 @NumberOfOperations(i64 0)
%17 = sext i32 %16 to i64
%18 = mul nsw i64 %15, %17
%19 = add nsw i64 %14, %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %3
br label %45
21: ; preds = %2
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = call i32 @NumberOfOperations(i64 %23)
%25 = sub nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = icmp eq i64 %22, %26
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i64, i64* %4
%30 = add nsw i64 %29, 1
%31 = trunc i64 %30 to i32
store i32 %31, i32* %3
br label %45
32: ; preds = %21
%33 = load i64, i64* %5
%34 = load i64, i64* %4
%35 = call i32 @NumberOfOperations(i64 %34)
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = icmp eq i64 %33, %37
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = load i64, i64* %4
%41 = sub nsw i64 2, %40
%42 = trunc i64 %41 to i32
store i32 %42, i32* %3
br label %45
43: ; preds = %32
br label %44
44: ; preds = %43
br label %45
45: ; preds = %12, %28, %39, %44
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @GetOperation(i64 %0, i64 %1) {
%3 = tail call i32 @NumberOfOperations(i64 %0)
%4 = add nsw i32 %3, -2
%5 = sext i32 %4 to i64
%6 = icmp sgt i64 %5, %1
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = add nsw i64 %1, 3
%9 = tail call i32 @NumberOfOperations(i64 0)
%10 = zext i32 %9 to i64
%11 = mul i64 %10, %0
%12 = add i64 %8, %11
%13 = trunc i64 %12 to i32
br label %30
14: ; preds = %2
%15 = tail call i32 @NumberOfOperations(i64 %0)
%16 = add nsw i32 %15, -2
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = trunc i64 %0 to i32
%21 = add i32 %20, 1
br label %30
22: ; preds = %14
%23 = tail call i32 @NumberOfOperations(i64 %0)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = icmp eq i64 %25, %1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = trunc i64 %0 to i32
%29 = sub i32 2, %28
br label %30
30: ; preds = %22, %7, %19, %27
%31 = phi i32 [ %13, %7 ], [ %21, %19 ], [ %29, %27 ], [ undef, %22 ]
ret i32 %31
}