#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 fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int detect_fat_size(FILE *image_file) {
  unsigned char preamble[3];
  if (!image_file) {
    return -1;
  }
  rewind(image_file);
  if (fread(preamble, 1, 3, image_file) != 3) {
    return -1;
  }
  if (preamble[0] == 0xEB && preamble[2] == 0x90) {
    return preamble[1] + 2;
  }
  return -1;
}


x86 assembly (clang, -O0):
<detect_fat_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <detect_fat_size+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <detect_fat_size+0x8c>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x13(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
cmp    $0x3,%eax
je     1178 <detect_fat_size+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <detect_fat_size+0x8c>
movzbl -0x13(%rbp),%eax
cmp    $0xeb,%eax
jne    11a5 <detect_fat_size+0x85>
movzbl -0x11(%rbp),%eax
cmp    $0x90,%eax
jne    11a5 <detect_fat_size+0x85>
movzbl -0x12(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <detect_fat_size+0x8c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_fat_size>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1167 <detect_fat_size+0x47>
mov    %rdi,%rbx
call   1040 <rewind@plt>
lea    0x5(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x3,%eax
jne    1167 <detect_fat_size+0x47>
cmpb   $0xeb,0x5(%rsp)
jne    1167 <detect_fat_size+0x47>
cmpb   $0x90,0x7(%rsp)
jne    1167 <detect_fat_size+0x47>
movzbl 0x6(%rsp),%ebp
add    $0x2,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @detect_fat_size(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [3 x i8]
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 -1, i32* %2
br label %32
8: ; preds = %1
%9 = load i32*, i32** %3
%10 = call i32 @rewind(i32* %9)
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i32 @fread(i8* %11, i32 1, i32 3, i32* %12)
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %16
15: ; preds = %8
store i32 -1, i32* %2
br label %32
16: ; preds = %8
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 235
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 144
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = add nsw i32 %29, 2
store i32 %30, i32* %2
br label %32
31: ; preds = %21, %16
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %26, %15, %7
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @detect_fat_size(i32* %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32* %0, null
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = tail call i32 @rewind(i32* %0)
%7 = call i32 @fread(i8* %3, i32 1, i32 3, i32* %0)
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, -21
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, -112
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = add nuw nsw i32 %19, 2
br label %21
21: ; preds = %9, %5, %1, %16
%22 = phi i32 [ %20, %16 ], [ -1, %1 ], [ -1, %5 ], [ -1, %9 ]
ret i32 %22
}