#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 get1key();
scalar_t__ in_check();
int in_get();
int /*<<< orphan*/ in_put(int);
int tcapgetc() {
  int c;
  if (in_check())
    return (in_get());
  c = get1key();
  if (0x0100 & c)
    c = (c & ~0x0100) - '@';
  if ((c & ~255) != 0) {
    in_put(0);
    in_put(c >> 8);
    in_put(c & 255);
    return (tcapgetc());
  }
  return (c);
}


x86 assembly (clang, -O0):
<tcapgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <in_check@plt>
cmp    $0x0,%rax
je     1178 <tcapgetc+0x28>
mov    $0x0,%al
call   1070 <in_get@plt>
mov    %eax,-0x4(%rbp)
jmp    11e5 <tcapgetc+0x95>
mov    $0x0,%al
call   1040 <get1key@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     11a1 <tcapgetc+0x51>
mov    -0x8(%rbp),%eax
and    $0xfffffeff,%eax
sub    $0x40,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffffff00,%eax
cmp    $0x0,%eax
je     11df <tcapgetc+0x8f>
xor    %edi,%edi
call   1060 <in_put@plt>
mov    -0x8(%rbp),%edi
sar    $0x8,%edi
call   1060 <in_put@plt>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
call   1060 <in_put@plt>
call   1050 <tcapgetc@plt>
mov    %eax,-0x4(%rbp)
jmp    11e5 <tcapgetc+0x95>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcapgetc>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <in_check@plt>
test   %rax,%rax
jne    1199 <tcapgetc+0x59>
xor    %eax,%eax
call   1040 <get1key@plt>
mov    %eax,%ebx
and    $0xfffffeff,%ebx
add    $0xffffffc0,%ebx
test   $0x100,%eax
cmove  %eax,%ebx
cmp    $0x100,%ebx
jb     11a1 <tcapgetc+0x61>
xor    %edi,%edi
call   1050 <in_put@plt>
mov    %ebx,%edi
sar    $0x8,%edi
call   1050 <in_put@plt>
movzbl %bl,%edi
call   1050 <in_put@plt>
jmp    1150 <tcapgetc+0x10>
xor    %eax,%eax
pop    %rbx
jmp    1060 <in_get@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @tcapgetc() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 (...) @in_check()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (...) @in_get()
store i32 %6, i32* %1
br label %31
7: ; preds = %0
%8 = call i32 (...) @get1key()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = and i32 256, %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %2
%14 = and i32 %13, -257
%15 = sub nsw i32 %14, 64
store i32 %15, i32* %2
br label %16
16: ; preds = %12, %7
%17 = load i32, i32* %2
%18 = and i32 %17, -256
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = call i32 @in_put(i32 0)
%22 = load i32, i32* %2
%23 = ashr i32 %22, 8
%24 = call i32 @in_put(i32 %23)
%25 = load i32, i32* %2
%26 = and i32 %25, 255
%27 = call i32 @in_put(i32 %26)
%28 = call i32 @tcapgetc()
store i32 %28, i32* %1
br label %31
29: ; preds = %16
%30 = load i32, i32* %2
store i32 %30, i32* %1
br label %31
31: ; preds = %29, %20, %5
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
define i32 @tcapgetc() {
%1 = tail call i64 (...) @in_check()
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %13, %0
%4 = tail call i32 (...) @in_get()
br label %21
5: ; preds = %0, %13
%6 = tail call i32 (...) @get1key()
%7 = and i32 %6, 256
%8 = icmp eq i32 %7, 0
%9 = and i32 %6, -257
%10 = add nsw i32 %9, -64
%11 = select i1 %8, i32 %6, i32 %10
%12 = icmp ult i32 %11, 256
br i1 %12, label %21, label %13
13: ; preds = %5
%14 = tail call i32 @in_put(i32 0)
%15 = ashr i32 %11, 8
%16 = tail call i32 @in_put(i32 %15)
%17 = and i32 %11, 255
%18 = tail call i32 @in_put(i32 %17)
%19 = tail call i64 (...) @in_check()
%20 = icmp eq i64 %19, 0
br i1 %20, label %5, label %3
21: ; preds = %5, %3
%22 = phi i32 [ %4, %3 ], [ %11, %5 ]
ret i32 %22
}