#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int h;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while (fscanf(fp, "%d ", &h) != EOF) {
    char c;
    int l = 0;
    while (1) {
      int cr = (l + h) % 2;
      fscanf(fp, "%c", &c);
      if (c == 'L') {
        h = (l + h) / 2 + cr - 1;
        fseek(fp, 5, SEEK_CUR);
      } else if (c == 'H') {
        l = (l + h) / 2 + cr + 1;
        fseek(fp, 6, SEEK_CUR);
      } else {
        printf("%d\n", (l + h) / 2 + cr);
        fseek(fp, 4, SEEK_CUR);
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1181 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cb <main+0x18b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
je     12c4 <main+0x184>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
lea    -0x1d(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movsbl -0x1d(%rbp),%eax
cmp    $0x4c,%eax
jne    1238 <main+0xf8>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1050 <fseek@plt>
jmp    12ba <main+0x17a>
movsbl -0x1d(%rbp),%eax
cmp    $0x48,%eax
jne    1278 <main+0x138>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1050 <fseek@plt>
jmp    12b5 <main+0x175>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    -0x28(%rbp),%esi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <fseek@plt>
jmp    12bf <main+0x17f>
jmp    12ba <main+0x17a>
jmp    11d1 <main+0x91>
jmp    11a4 <main+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1287 <main+0x147>
mov    0x8(%rsi),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xea6(%rip),%rsi
xor    %ebx,%ebx
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
je     129d <main+0x15d>
lea    0xe82(%rip),%r14
lea    0x3(%rsp),%r15
mov    0x2e46(%rip),%r13
jmp    1206 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x4(%rsp),%ebp
mov    %ebp,%esi
shr    $0x1f,%esi
add    %ebp,%esi
sar    %esi
add    %ebx,%esi
xor    %ebx,%ebx
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x4,%esi
call   1050 <fseek@plt>
mov    %r12,%rdi
lea    0xe2a(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
je     129d <main+0x15d>
xor    %ebp,%ebp
jmp    1234 <main+0xf4>
nopw   0x0(%rax,%rax,1)
add    0x4(%rsp),%ebp
mov    %ebp,%eax
shr    $0x1f,%eax
add    %ebp,%eax
sar    %eax
lea    (%rbx,%rax,1),%ebp
add    $0x1,%ebp
mov    $0x6,%esi
mov    0x0(%r13),%edx
mov    %r12,%rdi
call   1050 <fseek@plt>
mov    0x4(%rsp),%ebx
add    %ebp,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
and    $0xfffffffe,%eax
sub    %eax,%ebx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
movzbl 0x3(%rsp),%eax
cmp    $0x48,%al
je     1210 <main+0xd0>
cmp    $0x4c,%al
jne    11b0 <main+0x70>
mov    0x4(%rsp),%eax
add    %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
lea    (%rbx,%rcx,1),%eax
add    $0xffffffff,%eax
mov    %eax,0x4(%rsp)
mov    $0x5,%esi
jmp    1228 <main+0xe8>
mov    (%rsi),%rsi
lea    0xd6f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%d \00"
@EOF = global i64 0
@.str.3 = [3 x i8] c"%c\00"
@SEEK_CUR = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %80
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
br label %23
23: ; preds = %78, %18
%24 = load i32*, i32** %6
%25 = call i64 (i32*, i8*, ...) @fscanf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%26 = load i64, i64* @EOF
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %79
28: ; preds = %23
store i32 0, i32* %9
br label %29
29: ; preds = %28, %77
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = add nsw i32 %30, %31
%33 = srem i32 %32, 2
store i32 %33, i32* %10
%34 = load i32*, i32** %6
%35 = call i64 (i32*, i8*, ...) @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 76
br i1 %38, label %39, label %50
39: ; preds = %29
%40 = load i32, i32* %9
%41 = load i32, i32* %7
%42 = add nsw i32 %40, %41
%43 = sdiv i32 %42, 2
%44 = load i32, i32* %10
%45 = add nsw i32 %43, %44
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %7
%47 = load i32*, i32** %6
%48 = load i32, i32* @SEEK_CUR
%49 = call i32 @fseek(i32* %47, i32 5, i32 %48)
br label %77
50: ; preds = %29
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 72
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = load i32, i32* %9
%56 = load i32, i32* %7
%57 = add nsw i32 %55, %56
%58 = sdiv i32 %57, 2
%59 = load i32, i32* %10
%60 = add nsw i32 %58, %59
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
%62 = load i32*, i32** %6
%63 = load i32, i32* @SEEK_CUR
%64 = call i32 @fseek(i32* %62, i32 6, i32 %63)
br label %76
65: ; preds = %50
%66 = load i32, i32* %9
%67 = load i32, i32* %7
%68 = add nsw i32 %66, %67
%69 = sdiv i32 %68, 2
%70 = load i32, i32* %10
%71 = add nsw i32 %69, %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %71)
%73 = load i32*, i32** %6
%74 = load i32, i32* @SEEK_CUR
%75 = call i32 @fseek(i32* %73, i32 4, i32 %74)
br label %78
76: ; preds = %54
br label %77
77: ; preds = %76, %39
br label %29
78: ; preds = %65
br label %23
79: ; preds = %23
store i32 0, i32* %3
br label %80
80: ; preds = %79, %13
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%d \00"
@EOF = global i64 0
@.str.3 = [3 x i8] c"%c\00"
@SEEK_CUR = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %53
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 (i32*, i8*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %53, label %17
17: ; preds = %10, %42
br label %18
18: ; preds = %37, %17
%19 = phi i32 [ 0, %17 ], [ %39, %37 ]
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
%22 = srem i32 %21, 2
%23 = call i64 (i32*, i8*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%24 = load i8, i8* %4
switch i8 %24, label %42 [
i8 76, label %25
i8 72, label %31
]
25: ; preds = %18
%26 = load i32, i32* %3
%27 = add nsw i32 %26, %19
%28 = sdiv i32 %27, 2
%29 = add nsw i32 %22, -1
%30 = add nsw i32 %29, %28
store i32 %30, i32* %3
br label %37
31: ; preds = %18
%32 = load i32, i32* %3
%33 = add nsw i32 %32, %19
%34 = sdiv i32 %33, 2
%35 = add nsw i32 %22, 1
%36 = add nsw i32 %35, %34
br label %37
37: ; preds = %25, %31
%38 = phi i32 [ 5, %25 ], [ 6, %31 ]
%39 = phi i32 [ %19, %25 ], [ %36, %31 ]
%40 = load i32, i32* @SEEK_CUR
%41 = call i32 @fseek(i32* %13, i32 %38, i32 %40)
br label %18
42: ; preds = %18
%43 = load i32, i32* %3
%44 = add nsw i32 %43, %19
%45 = sdiv i32 %44, 2
%46 = add nsw i32 %45, %22
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @SEEK_CUR
%49 = call i32 @fseek(i32* %13, i32 4, i32 %48)
%50 = call i64 (i32*, i8*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%51 = load i64, i64* @EOF
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %17
53: ; preds = %42, %10, %7
%54 = phi i32 [ 1, %7 ], [ 0, %10 ], [ 0, %42 ]
ret i32 %54
}