#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;
int O_NONBLOCK;
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, void *);
int getchar();
int getbigchar() {
  int r = getchar();
  int 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    $0x10,%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    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1159 <getbigchar+0x39>
movl   $0x0,-0x8(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%eax
mov    0x2e7c(%rip),%rcx
or     (%rcx),%eax
movslq %eax,%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     119c <getbigchar+0x7c>
mov    -0x4(%rbp),%eax
shl    $0x7,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <getbigchar+0x58>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
movslq -0x8(%rbp),%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbigchar>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
cmove  %r14d,%ebp
mov    0x2e86(%rip),%r14
mov    (%r14),%esi
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
or     %ebp,%eax
movslq %eax,%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
nopw   0x0(%rax,%rax,1)
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    (%r14),%esi
movslq %ebp,%rdx
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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