#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 strling(int);
int solve(int k) {
  int case1, case2;
  int hi, lo, mid;
  lo = 1, hi = 1 << 22;
  mid = (lo + hi) / 2;
  while (lo <= hi) {
    case1 = k < strling(mid);
    case2 = k > strling(mid + 1);
    if (case1)
      hi = mid;
    else if (case2)
      lo = mid + 1;
    else
      return mid;
    mid = (lo + hi) / 2;
  }
  return lo;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x400000,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11dc <solve+0xcc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <strling@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1030 <strling@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119e <solve+0x8e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11c6 <solve+0xb6>
cmpl   $0x0,-0x10(%rbp)
je     11b6 <solve+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c1 <solve+0xb1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <solve+0xd2>
jmp    11c6 <solve+0xb6>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    113a <solve+0x2a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x400000,%r12d
mov    $0x1,%r13d
mov    $0x200000,%ebx
jmp    115d <solve+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r12d
mov    %r13d,%ebp
lea    (%r12,%rbp,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %ebp,%r13d
mov    %ebp,%eax
cmp    %r12d,%ebp
jg     117f <solve+0x6f>
mov    %ebx,%edi
call   1030 <strling@plt>
mov    %eax,%r15d
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
call   1030 <strling@plt>
cmp    %r14d,%r15d
jg     1140 <solve+0x30>
mov    %eax,%ecx
mov    %ebx,%eax
cmp    %r14d,%ecx
jl     1146 <solve+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @solve(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %7
store i32 4194304, i32* %6
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = add nsw i32 %9, %10
%12 = sdiv i32 %11, 2
store i32 %12, i32* %8
br label %13
13: ; preds = %42, %1
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load i32, i32* %3
%19 = load i32, i32* %8
%20 = call i32 @strling(i32 %19)
%21 = icmp slt i32 %18, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
%26 = call i32 @strling(i32 %25)
%27 = icmp sgt i32 %23, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %5
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = load i32, i32* %8
store i32 %32, i32* %6
br label %42
33: ; preds = %17
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %41
39: ; preds = %33
%40 = load i32, i32* %8
store i32 %40, i32* %2
br label %49
41: ; preds = %36
br label %42
42: ; preds = %41, %31
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = add nsw i32 %43, %44
%46 = sdiv i32 %45, 2
store i32 %46, i32* %8
br label %13
47: ; preds = %13
%48 = load i32, i32* %7
store i32 %48, i32* %2
br label %49
49: ; preds = %47, %39
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @solve(i32 %0) {
br label %2
2: ; preds = %1, %12
%3 = phi i32 [ 2097152, %1 ], [ %16, %12 ]
%4 = phi i32 [ 1, %1 ], [ %14, %12 ]
%5 = phi i32 [ 4194304, %1 ], [ %13, %12 ]
%6 = tail call i32 @strling(i32 %3)
%7 = icmp sgt i32 %6, %0
%8 = add nsw i32 %3, 1
%9 = tail call i32 @strling(i32 %8)
br i1 %7, label %12, label %10
10: ; preds = %2
%11 = icmp slt i32 %9, %0
br i1 %11, label %12, label %18
12: ; preds = %10, %2
%13 = phi i32 [ %3, %2 ], [ %5, %10 ]
%14 = phi i32 [ %4, %2 ], [ %8, %10 ]
%15 = add nsw i32 %14, %13
%16 = sdiv i32 %15, 2
%17 = icmp sgt i32 %14, %13
br i1 %17, label %18, label %2
18: ; preds = %12, %10
%19 = phi i32 [ %3, %10 ], [ %14, %12 ]
ret i32 %19
}