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

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int read_i32_be(FILE *f, int32_t *i) {
  int32_t t = 0;
  int k, c;
  if (!f)
    return -1;
  for (k = 0; k < 4; ++k) {
    if ((c = fgetc(f)) == EOF)
      return -1;
    t = ((t >> 8) & 0xffffff) | (c << 24);
  }
  if (i)
    *i = t;
  return 0;
}


x86 assembly (clang, -O0):
<read_i32_be>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113e <read_i32_be+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <read_i32_be+0xa5>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    119a <read_i32_be+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
jne    1176 <read_i32_be+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <read_i32_be+0xa5>
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
and    $0xffffff,%eax
mov    -0x24(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1145 <read_i32_be+0x35>
cmpq   $0x0,-0x18(%rbp)
je     11ae <read_i32_be+0x9e>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_i32_be>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1191 <read_i32_be+0x81>
mov    %rsi,%r14
mov    %rdi,%rbp
call   1030 <fgetc@plt>
mov    0x2eb1(%rip),%r13
cmp    0x0(%r13),%eax
je     1191 <read_i32_be+0x81>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1191 <read_i32_be+0x81>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1191 <read_i32_be+0x81>
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     1191 <read_i32_be+0x81>
xor    %ebx,%ebx
test   %r14,%r14
je     1191 <read_i32_be+0x81>
shl    $0x18,%r15d
shld   $0x18,%r15d,%r12d
mov    0x4(%rsp),%ecx
shld   $0x18,%r12d,%ecx
shld   $0x18,%ecx,%eax
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_i32_be(i32* %0, i32* writeonly %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %27, label %4
4: ; preds = %2
%5 = tail call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %4
%9 = tail call i32 @fgetc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %27, label %12
12: ; preds = %8
%13 = tail call i32 @fgetc(i32* %0)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %27, label %16
16: ; preds = %12
%17 = tail call i32 @fgetc(i32* %0)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %27, label %20
20: ; preds = %16
%21 = icmp eq i32* %1, null
br i1 %21, label %27, label %22
22: ; preds = %20
%23 = shl i32 %5, 24
%24 = tail call i32 @llvm.fshl.i32(i32 %9, i32 %23, i32 24)
%25 = tail call i32 @llvm.fshl.i32(i32 %13, i32 %24, i32 24)
%26 = tail call i32 @llvm.fshl.i32(i32 %17, i32 %25, i32 24)
store i32 %26, i32* %1
br label %27
27: ; preds = %4, %8, %12, %16, %20, %22, %2
%28 = phi i32 [ -1, %2 ], [ 0, %22 ], [ 0, %20 ], [ -1, %16 ], [ -1, %12 ], [ -1, %8 ], [ -1, %4 ]
ret i32 %28
}