#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ try(int, int);
int one_experiment(int s) {
  int max_to = 1;
  int num_fails = 0;
  for (;;) {
    if (try(s, max_to) == 0) {
      num_fails = 0;
      if (max_to >= 512) {
        return max_to;
      }
      max_to *= 2;
    } else {
      num_fails += 1;
      if (num_fails == 3) {
        break;
      }
    }
  }
  if (max_to == 1)
    return 0;
  int min_to = max_to / 2;
  for (;;) {
    if (max_to - min_to <= 2) {
      fprintf(stderr, "Intermediate result: %d\n", min_to);
      return min_to;
    }
    int candidate = (min_to + max_to) / 2;
    if (try(s, candidate) == 0) {
      min_to = candidate;
    } else {
      max_to = candidate;
    }
  }
}


x86 assembly (clang, -O0):
<one_experiment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <try@plt>
cmp    $0x0,%rax
jne    117b <one_experiment+0x5b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x200,-0xc(%rbp)
jl     116d <one_experiment+0x4d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122f <one_experiment+0x10f>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1198 <one_experiment+0x78>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jne    1193 <one_experiment+0x73>
jmp    119d <one_experiment+0x7d>
jmp    1198 <one_experiment+0x78>
jmp    1139 <one_experiment+0x19>
cmpl   $0x1,-0xc(%rbp)
jne    11b3 <one_experiment+0x93>
movl   $0x0,-0x4(%rbp)
jmp    122f <one_experiment+0x10f>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x2,%eax
jg     11f3 <one_experiment+0xd3>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe1d(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122f <one_experiment+0x10f>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <try@plt>
cmp    $0x0,%rax
jne    1224 <one_experiment+0x104>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122a <one_experiment+0x10a>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11c1 <one_experiment+0xa1>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<one_experiment>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x1,%ebx
nop
mov    %r15d,%edi
mov    %ebx,%esi
call   1040 <try@plt>
test   %rax,%rax
je     115d <one_experiment+0x3d>
mov    %r15d,%edi
mov    %ebx,%esi
call   1040 <try@plt>
test   %rax,%rax
je     115d <one_experiment+0x3d>
mov    %r15d,%edi
mov    %ebx,%esi
call   1040 <try@plt>
test   %rax,%rax
jne    117a <one_experiment+0x5a>
cmp    $0x1ff,%ebx
jg     1169 <one_experiment+0x49>
add    %ebx,%ebx
jmp    1130 <one_experiment+0x10>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
cmp    $0x1,%ebx
je     116c <one_experiment+0x4c>
mov    %ebx,%r14d
shr    $0x1f,%r14d
add    %ebx,%r14d
sar    %r14d
jmp    11a2 <one_experiment+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
mov    %ebx,%eax
sub    %r14d,%eax
cmp    $0x3,%eax
jl     11cd <one_experiment+0xad>
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <try@plt>
test   %rax,%rax
jne    11a0 <one_experiment+0x80>
mov    %ebp,%r14d
jmp    11a2 <one_experiment+0x82>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
mov    %r14d,%edx
call   1030 <fprintf@plt>
jmp    116c <one_experiment+0x4c>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Intermediate result: %d\0A\00"
define i32 @one_experiment(i32 %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i32 [ %9, %8 ], [ 1, %1 ]
%4 = tail call i64 @try(i32 %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %13, %10, %2
%7 = icmp sgt i32 %3, 511
br i1 %7, label %37, label %8
8: ; preds = %6
%9 = shl nsw i32 %3, 1
br label %2
10: ; preds = %2
%11 = tail call i64 @try(i32 %0, i32 %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %10
%14 = tail call i64 @try(i32 %0, i32 %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %6, label %16
16: ; preds = %13
%17 = icmp eq i32 %3, 1
br i1 %17, label %37, label %18
18: ; preds = %16
%19 = sdiv i32 %3, 2
%20 = sub nsw i32 %3, %19
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %26
22: ; preds = %26, %18
%23 = phi i32 [ %19, %18 ], [ %34, %26 ]
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %37
26: ; preds = %18, %26
%27 = phi i32 [ %34, %26 ], [ %19, %18 ]
%28 = phi i32 [ %33, %26 ], [ %3, %18 ]
%29 = add nsw i32 %27, %28
%30 = sdiv i32 %29, 2
%31 = tail call i64 @try(i32 %0, i32 %30)
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 %28, i32 %30
%34 = select i1 %32, i32 %30, i32 %27
%35 = sub nsw i32 %33, %34
%36 = icmp slt i32 %35, 3
br i1 %36, label %22, label %26
37: ; preds = %6, %16, %22
%38 = phi i32 [ %23, %22 ], [ 0, %16 ], [ %3, %6 ]
ret i32 %38
}