#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
long O_NONBLOCK;
long fcntl(int /*<<< orphan*/, int /*<<< orphan*/, void *);
int getchar();
int getbigchar() {
  int r = getchar();
  long flags;
  if ((flags = fcntl(0, F_GETFL, (void *)0)) == -1) {
    flags = 0;
  }
  fcntl(0, F_SETFL, (void *)(flags | O_NONBLOCK));
  int c;
  while ((c = getchar()) != -1)
    r = r * 128 + c;
  fcntl(0, F_SETFL, (void *)flags);
  return r;
}


x86 assembly (clang, -O0):
<getbigchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <fcntl@plt>
mov    %rax,-0x10(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    115c <getbigchar+0x3c>
movq   $0x0,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    0x2e78(%rip),%rax
or     (%rax),%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     119e <getbigchar+0x7e>
mov    -0x4(%rbp),%eax
shl    $0x7,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117a <getbigchar+0x5a>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbigchar>:
push   %r15
push   %r14
push   %rbx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rax,%r14
cmp    $0xffffffffffffffff,%rax
cmove  %r15,%r14
mov    0x2e83(%rip),%r15
mov    (%r15),%esi
mov    0x2e89(%rip),%rax
mov    (%rax),%rdx
or     %r14,%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xffffffff,%eax
je     1183 <getbigchar+0x63>
shl    $0x7,%ebx
add    %eax,%ebx
jmp    1170 <getbigchar+0x50>
mov    (%r15),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <fcntl@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
define i32 @getbigchar() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = call i32 (...) @getchar()
store i32 %4, i32* %1
%5 = load i32, i32* @F_GETFL
%6 = call i64 @fcntl(i32 0, i32 %5, i8* null)
store i64 %6, i64* %2
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i64 0, i64* %2
br label %9
9: ; preds = %8, %0
%10 = load i32, i32* @F_SETFL
%11 = load i64, i64* %2
%12 = load i64, i64* @O_NONBLOCK
%13 = or i64 %11, %12
%14 = inttoptr i64 %13 to i8*
%15 = call i64 @fcntl(i32 0, i32 %10, i8* %14)
br label %16
16: ; preds = %19, %9
%17 = call i32 (...) @getchar()
store i32 %17, i32* %3
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %1
%21 = mul nsw i32 %20, 128
%22 = load i32, i32* %3
%23 = add nsw i32 %21, %22
store i32 %23, i32* %1
br label %16
24: ; preds = %16
%25 = load i32, i32* @F_SETFL
%26 = load i64, i64* %2
%27 = inttoptr i64 %26 to i8*
%28 = call i64 @fcntl(i32 0, i32 %25, i8* %27)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
define i32 @getbigchar() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @F_GETFL
%3 = tail call i64 @fcntl(i32 0, i32 %2, i8* null)
%4 = icmp eq i64 %3, -1
%5 = select i1 %4, i64 0, i64 %3
%6 = load i32, i32* @F_SETFL
%7 = load i64, i64* @O_NONBLOCK
%8 = or i64 %5, %7
%9 = inttoptr i64 %8 to i8*
%10 = tail call i64 @fcntl(i32 0, i32 %6, i8* %9)
%11 = tail call i32 (...) @getchar()
%12 = icmp eq i32 %11, -1
br i1 %12, label %20, label %13
13: ; preds = %0, %13
%14 = phi i32 [ %18, %13 ], [ %11, %0 ]
%15 = phi i32 [ %17, %13 ], [ %1, %0 ]
%16 = shl nsw i32 %15, 7
%17 = add nsw i32 %16, %14
%18 = tail call i32 (...) @getchar()
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %13
20: ; preds = %13, %0
%21 = phi i32 [ %1, %0 ], [ %17, %13 ]
%22 = load i32, i32* @F_SETFL
%23 = inttoptr i64 %5 to i8*
%24 = tail call i64 @fcntl(i32 0, i32 %22, i8* %23)
ret i32 %21
}