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

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
size_t read_bin(uint8_t *code, FILE *stream) {
  size_t nb;
  size_t i;
  for (i = 0; i < 65536; i++) {
    int c;
    c = fgetc(stream);
    if (c == EOF)
      break;
    code[i] = (uint8_t)c;
  }
  nb = i;
  for (; i < 65536; i++)
    code[i] = 0;
  return nb;
}


x86 assembly (clang, -O0):
<read_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x10000,-0x20(%rbp)
jae    117a <read_bin+0x6a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e9c(%rip),%rcx
cmp    (%rcx),%eax
jne    1159 <read_bin+0x49>
jmp    117a <read_bin+0x6a>
movslq -0x24(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <read_bin+0x18>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x10000,-0x20(%rbp)
jae    11b1 <read_bin+0xa1>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1182 <read_bin+0x72>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x80000,%r14d
xor    %ebx,%ebx
mov    0x2eaa(%rip),%r13
xchg   %ax,%ax
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1165 <read_bin+0x45>
cltq
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
add    $0xfffffffffffffff8,%r14
jne    1140 <read_bin+0x20>
mov    $0x10000,%ebx
jmp    117c <read_bin+0x5c>
cmp    $0xffff,%rbx
ja     117c <read_bin+0x5c>
lea    (%r15,%rbx,8),%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i64 @read_bin(i64* %0, i32* %1) {
%3 = alloca i64*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64* %0, i64** %3
store i32* %1, i32** %4
store i64 0, i64* %6
br label %8
8: ; preds = %24, %2
%9 = load i64, i64* %6
%10 = icmp ult i64 %9, 65536
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32*, i32** %4
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
br label %27
18: ; preds = %11
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = load i64*, i64** %3
%22 = load i64, i64* %6
%23 = getelementptr inbounds i64, i64* %21, i64 %22
store i64 %20, i64* %23
br label %24
24: ; preds = %18
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %8
27: ; preds = %17, %8
%28 = load i64, i64* %6
store i64 %28, i64* %5
br label %29
29: ; preds = %36, %27
%30 = load i64, i64* %6
%31 = icmp ult i64 %30, 65536
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i64*, i64** %3
%34 = load i64, i64* %6
%35 = getelementptr inbounds i64, i64* %33, i64 %34
store i64 0, i64* %35
br label %36
36: ; preds = %32
%37 = load i64, i64* %6
%38 = add i64 %37, 1
store i64 %38, i64* %6
br label %29
39: ; preds = %29
%40 = load i64, i64* %5
ret i64 %40
}

LLVM IR (-O2):
@EOF = global i32 0
define i64 @read_bin(i64* nocapture writeonly %0, i32* nocapture %1) {
br label %3
3: ; preds = %2, %8
%4 = phi i64 [ 0, %2 ], [ %11, %8 ]
%5 = tail call i32 @fgetc(i32* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i64, i64* %0, i64 %4
store i64 %9, i64* %10
%11 = add nuw nsw i64 %4, 1
%12 = icmp eq i64 %11, 65536
br i1 %12, label %20, label %3
13: ; preds = %3
%14 = icmp ult i64 %4, 65536
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = getelementptr i64, i64* %0, i64 %4
%17 = bitcast i64* %16 to i8*
%18 = mul nsw i64 %4, -8
%19 = add nsw i64 %18, 524288
br label %20
20: ; preds = %8, %15, %13
%21 = phi i64 [ %4, %15 ], [ %4, %13 ], [ 65536, %8 ]
ret i64 %21
}