#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
size_t read_once(int /*<<< orphan*/ **, size_t *, size_t *, int, char const *);
int /*<<< orphan*/ round_up(size_t);
scalar_t__ xrealloc(int /*<<< orphan*/ *, int /*<<< orphan*/);
size_t read_all_stdin(size_t stat_size, uint8_t **buf, const char *argv0) {
  size_t capacity = 0;
  size_t bytes_read = 0;
  *buf = (uint8_t *)xrealloc(NULL, round_up(stat_size + 1));
  if (stat_size & ~0xffffull)
    read_once(buf, &capacity, &bytes_read, stat_size & ~0xffffull, argv0);
  size_t r = 0;
  do {
    r = read_once(buf, &capacity, &bytes_read, 0x10000ull, argv0);
  } while (r);
  assert(capacity > bytes_read);
  return bytes_read;
}


x86 assembly (clang, -O0):
<read_all_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1030 <round_up@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
and    $0xffffffffffff0000,%rax
cmp    $0x0,%rax
je     11bb <read_all_stdin+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
and    $0xffffffffffff0000,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%r8
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <read_once@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%r8
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x10000,%ecx
call   1060 <read_once@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c3 <read_all_stdin+0x83>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_all_stdin>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
add    $0x1,%rdi
call   1030 <round_up@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <xrealloc@plt>
mov    %rax,(%rbx)
and    $0xffffffffffff0000,%r15
je     119c <read_all_stdin+0x5c>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15d,%ecx
mov    %r14,%r8
call   1060 <read_once@plt>
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    $0x10000,%ecx
mov    %r14,%r8
call   1060 <read_once@plt>
test   %rax,%rax
jne    11b0 <read_all_stdin+0x70>
mov    0x10(%rsp),%rax
xor    %edi,%edi
cmp    0x8(%rsp),%rax
seta   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @read_all_stdin(i64 %0, i32** %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %4
store i32** %1, i32*** %5
store i8* %2, i8** %6
store i64 0, i64* %7
store i64 0, i64* %8
%10 = load i64, i64* %4
%11 = add i64 %10, 1
%12 = call i32 @round_up(i64 %11)
%13 = call i64 @xrealloc(i32* null, i32 %12)
%14 = inttoptr i64 %13 to i32*
%15 = load i32**, i32*** %5
store i32* %14, i32** %15
%16 = load i64, i64* %4
%17 = and i64 %16, -65536
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %3
%20 = load i32**, i32*** %5
%21 = load i64, i64* %4
%22 = and i64 %21, -65536
%23 = trunc i64 %22 to i32
%24 = load i8*, i8** %6
%25 = call i64 @read_once(i32** %20, i64* %7, i64* %8, i32 %23, i8* %24)
br label %26
26: ; preds = %19, %3
store i64 0, i64* %9
br label %27
27: ; preds = %31, %26
%28 = load i32**, i32*** %5
%29 = load i8*, i8** %6
%30 = call i64 @read_once(i32** %28, i64* %7, i64* %8, i32 65536, i8* %29)
store i64 %30, i64* %9
br label %31
31: ; preds = %27
%32 = load i64, i64* %9
%33 = icmp ne i64 %32, 0
br i1 %33, label %27, label %34
34: ; preds = %31
%35 = load i64, i64* %7
%36 = load i64, i64* %8
%37 = icmp ugt i64 %35, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i64, i64* %8
ret i64 %40
}

LLVM IR (-O2):
define i64 @read_all_stdin(i64 %0, i32** %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = add i64 %0, 1
%9 = tail call i32 @round_up(i64 %8)
%10 = tail call i64 @xrealloc(i32* null, i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %1
%12 = and i64 %0, -65536
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = trunc i64 %12 to i32
%16 = call i64 @read_once(i32** %1, i64* %4, i64* %5, i32 %15, i8* %2)
br label %17
17: ; preds = %14, %3
br label %18
18: ; preds = %17, %18
%19 = call i64 @read_once(i32** %1, i64* %4, i64* %5, i32 65536, i8* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %18
21: ; preds = %18
%22 = load i64, i64* %4
%23 = load i64, i64* %5
%24 = icmp ugt i64 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i64, i64* %5
ret i64 %27
}