#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char a[] = "abcdefghijkmn", c;
  int left = 0, right = strlen(a) - 1, mid = (left + right) / 2;
  scanf("%c", &c);
  for (; left < right;) {
    if (a[mid] == c)
      break;
    if (a[mid] > c)
      right = mid - 1;
    else
      left = mid + 1;
    mid = (left + right) / 2;
  }
  if (a[mid] == c)
    printf("it is %d", mid + 1);
  else
    printf("not find!");
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
lea    0xe72(%rip),%rdi
lea    -0x13(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120d <main+0xcd>
movslq -0x20(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
movsbl -0x13(%rbp),%ecx
cmp    %ecx,%eax
jne    11cb <main+0x8b>
jmp    120d <main+0xcd>
movslq -0x20(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
movsbl -0x13(%rbp),%ecx
cmp    %ecx,%eax
jle    11ee <main+0xae>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <main+0xb7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
jmp    11a5 <main+0x65>
movslq -0x20(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
movsbl -0x13(%rbp),%ecx
cmp    %ecx,%eax
jne    123b <main+0xfb>
mov    -0x20(%rbp),%esi
add    $0x1,%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1249 <main+0x109>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x6e6d6b6a696867,%rax
mov    %rax,0xe(%rsp)
movabs $0x6867666564636261,%rax
66 67 68
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%ebx
lea    0xe91(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1060 <scanf@plt>
mov    %ebx,%eax
shr    $0x1f,%eax
lea    (%r14,%rax,1),%esi
add    $0xffffffff,%esi
sar    %esi
mov    0x7(%rsp),%al
cmp    $0x2,%r14d
jl     11da <main+0x9a>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %esi,%rdx
movzbl 0x8(%rsp,%rdx,1),%edx
cmp    %al,%dl
je     11da <main+0x9a>
lea    -0x1(%rsi),%edi
add    $0x1,%esi
cmp    %al,%dl
cmovle %esi,%ecx
cmovg  %edi,%ebx
lea    (%rcx,%rbx,1),%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
cmp    %ebx,%ecx
jl     11b0 <main+0x70>
movslq %esi,%rcx
cmp    %al,0x8(%rsp,%rcx,1)
jne    11f6 <main+0xb6>
add    $0x1,%esi
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1204 <main+0xc4>
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [14 x i8] c"abcdefghijkmn\00"
@.str = [3 x i8] c"%c\00"
@.str.1 = [9 x i8] c"it is %d\00"
@.str.2 = [10 x i8] c"not find!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [14 x i8]* %2 to i8*
store i32 0, i32* %4
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = add nsw i32 %11, %12
%14 = sdiv i32 %13, 2
store i32 %14, i32* %6
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %45, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %20
br label %50
30: ; preds = %20
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = icmp sgt i32 %35, %37
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %5
br label %45
42: ; preds = %30
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = add nsw i32 %46, %47
%49 = sdiv i32 %48, 2
store i32 %49, i32* %6
br label %16
50: ; preds = %29, %16
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = load i8, i8* %3
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %55, %57
br i1 %58, label %59, label %63
59: ; preds = %50
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %65
63: ; preds = %50
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = call i32 (...) @getchar()
%67 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [14 x i8] c"abcdefghijkmn\00"
@.str = [3 x i8] c"%c\00"
@.str.1 = [9 x i8] c"it is %d\00"
@.str.2 = [10 x i8] c"not find!\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, -1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%7 = sdiv i32 %5, 2
%8 = icmp sgt i32 %4, 1
%9 = load i8, i8* %2
br i1 %8, label %10, label %27
10: ; preds = %0, %18
%11 = phi i32 [ %25, %18 ], [ %7, %0 ]
%12 = phi i32 [ %23, %18 ], [ %5, %0 ]
%13 = phi i32 [ %22, %18 ], [ 0, %0 ]
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, %9
br i1 %17, label %27, label %18
18: ; preds = %10
%19 = icmp sgt i8 %16, %9
%20 = add nsw i32 %11, -1
%21 = add nsw i32 %11, 1
%22 = select i1 %19, i32 %13, i32 %21
%23 = select i1 %19, i32 %20, i32 %12
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %24, 2
%26 = icmp slt i32 %22, %23
br i1 %26, label %10, label %27
27: ; preds = %18, %10, %0
%28 = phi i32 [ %7, %0 ], [ %11, %10 ], [ %25, %18 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, %9
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = add nsw i32 %28, 1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %38
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = call i32 (...) @getchar()
%40 = call i32 (...) @getchar()
ret i32 0
}