#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 gapCalc {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gapCalcCost(struct gapCalc *, int, int);
int /*<<< orphan*/ verbose(int, char *, int, int, int /*<<< orphan*/, ...);
void gapCalcTest(struct gapCalc *gapCalc) {
  int i;
  for (i = 1; i <= 10; i++) {
    verbose(1, "%d: %d %d %d\n", i, gapCalcCost(gapCalc, i, 0),
            gapCalcCost(gapCalc, 0, i), gapCalcCost(gapCalc, i / 2, i - i / 2));
  }
  for (i = 1;; i *= 10) {
    verbose(1, "%d: %d %d %d\n", i, gapCalcCost(gapCalc, i, 0),
            gapCalcCost(gapCalc, 0, i), gapCalcCost(gapCalc, i / 2, i - i / 2));
    if (i == 1000000000)
      break;
  }
  verbose(1, "%d %d cost %d\n", 6489540, 84240,
          gapCalcCost(gapCalc, 84240, 6489540));
  verbose(1, "%d %d cost %d\n", 2746361, 1075188,
          gapCalcCost(gapCalc, 1075188, 2746361));
  verbose(1, "%d %d cost %d\n", 6489540 + 2746361 + 72, 84240 + 1075188 + 72,
          gapCalcCost(gapCalc, 84240 + 1075188 + 72, 6489540 + 2746361 + 72));
}


x86 assembly (clang, -O0):
<gapCalcTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     11bf <gapCalcTest+0x9f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <gapCalcCost@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%edx
sub    %eax,%edx
call   1030 <gapCalcCost@plt>
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    %eax,%r9d
mov    $0x1,%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <verbose@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <gapCalcTest+0x13>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <gapCalcCost@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%edx
sub    %eax,%edx
call   1030 <gapCalcCost@plt>
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    %eax,%r9d
mov    $0x1,%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1040 <verbose@plt>
cmpl   $0x3b9aca00,-0xc(%rbp)
jne    124c <gapCalcTest+0x12c>
jmp    125d <gapCalcTest+0x13d>
jmp    1251 <gapCalcTest+0x131>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <gapCalcTest+0xa6>
mov    -0x8(%rbp),%rdi
mov    $0x14910,%esi
mov    $0x6305c4,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xd8f(%rip),%rsi
mov    $0x6305c4,%edx
mov    $0x14910,%ecx
mov    $0x0,%al
call   1040 <verbose@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1067f4,%esi
mov    $0x29e7f9,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xd5c(%rip),%rsi
mov    $0x29e7f9,%edx
mov    $0x1067f4,%ecx
mov    $0x0,%al
call   1040 <verbose@plt>
mov    -0x8(%rbp),%rdi
mov    $0x11b14c,%esi
mov    $0x8cee05,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xd29(%rip),%rsi
mov    $0x8cee05,%edx
mov    $0x11b14c,%ecx
mov    $0x0,%al
call   1040 <verbose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gapCalcTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%ebx
lea    0xec6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ebp
shr    %ebp
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r13d
mov    %ebx,%edx
sub    %ebp,%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <gapCalcCost@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <verbose@plt>
add    $0x1,%ebx
cmp    $0xb,%ebx
jne    1140 <gapCalcTest+0x20>
mov    $0x1,%ebx
lea    0xe62(%rip),%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <gapCalcCost@plt>
mov    %eax,%ebp
mov    %ebx,%esi
shr    %esi
mov    %ebx,%edx
sub    %esi,%edx
mov    %r14,%rdi
call   1030 <gapCalcCost@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <verbose@plt>
cmp    $0x3b9aca00,%ebx
je     11f6 <gapCalcTest+0xd6>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
jmp    11a0 <gapCalcTest+0x80>
mov    %r14,%rdi
mov    $0x14910,%esi
mov    $0x6305c4,%edx
call   1030 <gapCalcCost@plt>
lea    0xdff(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x6305c4,%edx
mov    $0x14910,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <verbose@plt>
mov    %r14,%rdi
mov    $0x1067f4,%esi
mov    $0x29e7f9,%edx
call   1030 <gapCalcCost@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x29e7f9,%edx
mov    $0x1067f4,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <verbose@plt>
mov    %r14,%rdi
mov    $0x11b14c,%esi
mov    $0x8cee05,%edx
call   1030 <gapCalcCost@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x8cee05,%edx
mov    $0x11b14c,%ecx
mov    %eax,%r8d
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <verbose@plt>

LLVM IR (-O0):
%struct.gapCalc = type { i32 }
@.str = [14 x i8] c"%d: %d %d %d\0A\00"
@.str.1 = [15 x i8] c"%d %d cost %d\0A\00"
define void @gapCalcTest(%struct.gapCalc* %0) {
%2 = alloca %struct.gapCalc*
%3 = alloca i32
store %struct.gapCalc* %0, %struct.gapCalc** %2
store i32 1, i32* %3
br label %4
4: ; preds = %24, %1
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 10
br i1 %6, label %7, label %27
7: ; preds = %4
%8 = load i32, i32* %3
%9 = load %struct.gapCalc*, %struct.gapCalc** %2
%10 = load i32, i32* %3
%11 = call i32 @gapCalcCost(%struct.gapCalc* %9, i32 %10, i32 0)
%12 = load %struct.gapCalc*, %struct.gapCalc** %2
%13 = load i32, i32* %3
%14 = call i32 @gapCalcCost(%struct.gapCalc* %12, i32 0, i32 %13)
%15 = load %struct.gapCalc*, %struct.gapCalc** %2
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
%18 = load i32, i32* %3
%19 = load i32, i32* %3
%20 = sdiv i32 %19, 2
%21 = sub nsw i32 %18, %20
%22 = call i32 @gapCalcCost(%struct.gapCalc* %15, i32 %17, i32 %21)
%23 = call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %14, i32 %22)
br label %24
24: ; preds = %7
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %4
27: ; preds = %4
store i32 1, i32* %3
br label %28
28: ; preds = %49, %27
%29 = load i32, i32* %3
%30 = load %struct.gapCalc*, %struct.gapCalc** %2
%31 = load i32, i32* %3
%32 = call i32 @gapCalcCost(%struct.gapCalc* %30, i32 %31, i32 0)
%33 = load %struct.gapCalc*, %struct.gapCalc** %2
%34 = load i32, i32* %3
%35 = call i32 @gapCalcCost(%struct.gapCalc* %33, i32 0, i32 %34)
%36 = load %struct.gapCalc*, %struct.gapCalc** %2
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 2
%39 = load i32, i32* %3
%40 = load i32, i32* %3
%41 = sdiv i32 %40, 2
%42 = sub nsw i32 %39, %41
%43 = call i32 @gapCalcCost(%struct.gapCalc* %36, i32 %38, i32 %42)
%44 = call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %32, i32 %35, i32 %43)
%45 = load i32, i32* %3
%46 = icmp eq i32 %45, 1000000000
br i1 %46, label %47, label %48
47: ; preds = %28
br label %52
48: ; preds = %28
br label %49
49: ; preds = %48
%50 = load i32, i32* %3
%51 = mul nsw i32 %50, 10
store i32 %51, i32* %3
br label %28
52: ; preds = %47
%53 = load %struct.gapCalc*, %struct.gapCalc** %2
%54 = call i32 @gapCalcCost(%struct.gapCalc* %53, i32 84240, i32 6489540)
%55 = call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 6489540, i32 84240, i32 %54)
%56 = load %struct.gapCalc*, %struct.gapCalc** %2
%57 = call i32 @gapCalcCost(%struct.gapCalc* %56, i32 1075188, i32 2746361)
%58 = call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 2746361, i32 1075188, i32 %57)
%59 = load %struct.gapCalc*, %struct.gapCalc** %2
%60 = call i32 @gapCalcCost(%struct.gapCalc* %59, i32 1159500, i32 9235973)
%61 = call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 9235973, i32 1159500, i32 %60)
ret void
}

LLVM IR (-O2):
%struct.gapCalc = type { i32 }
@.str = [14 x i8] c"%d: %d %d %d\0A\00"
@.str.1 = [15 x i8] c"%d %d cost %d\0A\00"
define void @gapCalcTest(%struct.gapCalc* %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 1, %1 ], [ %10, %2 ]
%4 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 %3, i32 0)
%5 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 0, i32 %3)
%6 = lshr i32 %3, 1
%7 = sub nsw i32 %3, %6
%8 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 %6, i32 %7)
%9 = tail call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4, i32 %5, i32 %8)
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 11
br i1 %11, label %12, label %2
12: ; preds = %2, %21
%13 = phi i32 [ %22, %21 ], [ 1, %2 ]
%14 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 %13, i32 0)
%15 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 0, i32 %13)
%16 = lshr i32 %13, 1
%17 = sub nsw i32 %13, %16
%18 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 %16, i32 %17)
%19 = tail call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %18)
%20 = icmp eq i32 %13, 1000000000
br i1 %20, label %23, label %21
21: ; preds = %12
%22 = mul nsw i32 %13, 10
br label %12
23: ; preds = %12
%24 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 84240, i32 6489540)
%25 = tail call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 6489540, i32 84240, i32 %24)
%26 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 1075188, i32 2746361)
%27 = tail call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 2746361, i32 1075188, i32 %26)
%28 = tail call i32 @gapCalcCost(%struct.gapCalc* %0, i32 1159500, i32 9235973)
%29 = tail call i32 (i32, i8*, i32, i32, i32, ...) @verbose(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 9235973, i32 1159500, i32 %28)
ret void
}