#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 getbits2(int, int);
int getc2(unsigned char *node, int handle) {
  int next;
  while (node[1] != 0) {
    if (getbits2(1, handle)) {
      next = node[1] & 0xf;
      if (next == 0)
        return (getbits2(8, handle) | 0x100);
    } else
      next = node[1] >> 4;
    node += next * 2;
  }
  return (int)*node;
}


x86 assembly (clang, -O0):
<getc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11a4 <getc2+0x94>
mov    -0x14(%rbp),%esi
mov    $0x1,%edi
call   1030 <getbits2@plt>
cmp    $0x0,%eax
je     117d <getc2+0x6d>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1178 <getc2+0x68>
mov    -0x14(%rbp),%esi
mov    $0x8,%edi
call   1030 <getbits2@plt>
or     $0x100,%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <getc2+0x9e>
jmp    118b <getc2+0x7b>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
sar    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    111f <getc2+0xf>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getc2>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,0x1(%rdi)
je     1160 <getc2+0x50>
mov    %esi,%ebp
jmp    1134 <getc2+0x24>
shr    $0x4,%cl
movzbl %cl,%ecx
lea    (%rbx,%rcx,2),%rax
cmpb   $0x0,0x1(%rbx,%rcx,2)
mov    %rax,%rbx
je     1163 <getc2+0x53>
mov    $0x1,%edi
mov    %ebp,%esi
call   1030 <getbits2@plt>
movzbl 0x1(%rbx),%ecx
test   %eax,%eax
je     1120 <getc2+0x10>
and    $0xf,%cl
jne    1123 <getc2+0x13>
mov    $0x8,%edi
mov    %ebp,%esi
call   1030 <getbits2@plt>
or     $0x100,%eax
jmp    1166 <getc2+0x56>
mov    %rbx,%rax
movzbl (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getc2(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
br label %7
7: ; preds = %36, %2
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %7
%14 = load i32, i32* %5
%15 = call i32 @getbits2(i32 1, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 15
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* %5
%27 = call i32 @getbits2(i32 8, i32 %26)
%28 = or i32 %27, 256
store i32 %28, i32* %3
br label %46
29: ; preds = %17
br label %36
30: ; preds = %13
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = ashr i32 %34, 4
store i32 %35, i32* %6
br label %36
36: ; preds = %30, %29
%37 = load i32, i32* %6
%38 = mul nsw i32 %37, 2
%39 = load i8*, i8** %4
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %4
br label %7
42: ; preds = %7
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %25
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @getc2(i8* nocapture %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %2, %20
%7 = phi i8* [ %25, %20 ], [ %3, %2 ]
%8 = phi i8* [ %24, %20 ], [ %0, %2 ]
%9 = tail call i32 @getbits2(i32 1, i32 %1)
%10 = icmp eq i32 %9, 0
%11 = load i8, i8* %7
br i1 %10, label %18, label %12
12: ; preds = %6
%13 = and i8 %11, 15
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = tail call i32 @getbits2(i32 8, i32 %1)
%17 = or i32 %16, 256
br label %32
18: ; preds = %6
%19 = lshr i8 %11, 4
br label %20
20: ; preds = %12, %18
%21 = phi i8 [ %13, %12 ], [ %19, %18 ]
%22 = shl nuw nsw i8 %21, 1
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds i8, i8* %8, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %6
28: ; preds = %20, %2
%29 = phi i8* [ %0, %2 ], [ %24, %20 ]
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
br label %32
32: ; preds = %28, %15
%33 = phi i32 [ %17, %15 ], [ %31, %28 ]
ret i32 %33
}