#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 EOF;
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
size_t get_input(int *buffer) {
  int c;
  size_t i = 0;
  while ((c = getc(stdin)) != EOF && i < 2048) {
    buffer[i++] = c;
  }
  return i == 0 ? 0 : i - 1;
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2ea0(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1159 <get_input+0x49>
cmpq   $0x800,-0x18(%rbp)
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1169 <get_input+0x59>
jmp    1187 <get_input+0x77>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %edx,(%rax,%rcx,4)
jmp    1124 <get_input+0x14>
cmpq   $0x0,-0x18(%rbp)
jne    119d <get_input+0x8d>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11a9 <get_input+0x99>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2ec5(%rip),%r15
mov    (%r15),%edi
call   1030 <getc@plt>
mov    0x2eae(%rip),%r12
cmp    (%r12),%eax
jne    113d <get_input+0x2d>
xor    %r13d,%r13d
jmp    1166 <get_input+0x56>
xor    %ebx,%ebx
nop
lea    0x1(%rbx),%r13
mov    %eax,(%r14,%rbx,4)
mov    (%r15),%edi
call   1030 <getc@plt>
cmp    (%r12),%eax
je     1162 <get_input+0x52>
cmp    $0x7ff,%rbx
mov    %r13,%rbx
jb     1140 <get_input+0x30>
add    $0xffffffffffffffff,%r13
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i64 @get_input(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
store i32* %0, i32** %2
store i64 0, i64* %4
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* @stdin
%7 = call i32 @getc(i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i64, i64* %4
%12 = icmp ult i64 %11, 2048
br label %13
13: ; preds = %10, %5
%14 = phi i1 [ false, %5 ], [ %12, %10 ]
br i1 %14, label %15, label %21
15: ; preds = %13
%16 = load i32, i32* %3
%17 = load i32*, i32** %2
%18 = load i64, i64* %4
%19 = add i64 %18, 1
store i64 %19, i64* %4
%20 = getelementptr inbounds i32, i32* %17, i64 %18
store i32 %16, i32* %20
br label %5
21: ; preds = %13
%22 = load i64, i64* %4
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %28
25: ; preds = %21
%26 = load i64, i64* %4
%27 = sub i64 %26, 1
br label %28
28: ; preds = %25, %24
%29 = phi i64 [ 0, %24 ], [ %27, %25 ]
ret i64 %29
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i64 @get_input(i32* nocapture writeonly %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32 @getc(i32 %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %12, %6 ], [ %3, %1 ]
%8 = phi i64 [ %9, %6 ], [ 0, %1 ]
%9 = add nuw nsw i64 %8, 1
%10 = getelementptr inbounds i32, i32* %0, i64 %8
store i32 %7, i32* %10
%11 = load i32, i32* @stdin
%12 = tail call i32 @getc(i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
%15 = icmp ult i64 %8, 2047
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %6, label %17
17: ; preds = %6, %1
%18 = phi i64 [ 0, %1 ], [ %8, %6 ]
ret i64 %18
}