#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*/ FILE;

/* Variables and functions */
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int fgetint(FILE *fptr) {
  int low = fgetc(fptr);
  int hi = fgetc(fptr);
  int val = (hi << 8) + low;
  if (val > 4096) {
    fprintf(stderr, "    Error: canfromfile: strange int val: %d\n", val);
    return 4096;
  }
  return val;
}


x86 assembly (clang, -O0):
<fgetint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1000,-0x1c(%rbp)
jle    1181 <fgetint+0x61>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1000,-0x4(%rbp)
jmp    1187 <fgetint+0x67>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetint>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
shl    $0x8,%eax
add    %ebp,%eax
cmp    $0x1001,%eax
jl     115d <fgetint+0x3d>
mov    0x2e98(%rip),%rcx
mov    (%rcx),%edi
lea    0xeaf(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
mov    $0x1000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c" Error: canfromfile: strange int val: %d\0A\00"
define i32 @fgetint(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %4
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = shl i32 %11, 8
%13 = load i32, i32* %4
%14 = add nsw i32 %12, %13
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 4096
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i32, i32* %6
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 4096, i32* %2
br label %23
21: ; preds = %1
%22 = load i32, i32* %6
store i32 %22, i32* %2
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c" Error: canfromfile: strange int val: %d\0A\00"
define i32 @fgetint(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = tail call i32 @fgetc(i32* %0)
%4 = shl i32 %3, 8
%5 = add nsw i32 %4, %2
%6 = icmp sgt i32 %5, 4096
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %10
10: ; preds = %1, %7
%11 = phi i32 [ 4096, %7 ], [ %5, %1 ]
ret i32 %11
}