#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 EOF;
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int unicoder_decodeBom(unsigned char *);
int unicoder_decodeBomFromFile(FILE *f) {
  int i, currChar;
  long originalPosition;
  unsigned char bytes[4];
  if (f == NULL)
    return -64;
  originalPosition = ftell(f);
  fseek(f, 0, SEEK_SET);
  for (i = 0; i < 4; i++)
    bytes[i] = 0;
  for (i = 0; i < 4; i++) {
    currChar = fgetc(f);
    if (currChar == EOF)
      break;
    else
      bytes[i] = (unsigned char)currChar;
  }
  fseek(f, originalPosition, SEEK_SET);
  return unicoder_decodeBom(bytes);
}


x86 assembly (clang, -O0):
<unicoder_decodeBomFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <unicoder_decodeBomFromFile+0x23>
movl   $0xffffffc0,-0x4(%rbp)
jmp    1224 <unicoder_decodeBomFromFile+0xe4>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11ae <unicoder_decodeBomFromFile+0x6e>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x24(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <unicoder_decodeBomFromFile+0x4d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1202 <unicoder_decodeBomFromFile+0xc2>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%eax
jne    11e2 <unicoder_decodeBomFromFile+0xa2>
jmp    1202 <unicoder_decodeBomFromFile+0xc2>
mov    -0x18(%rbp),%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x24(%rbp,%rax,1)
jmp    11f4 <unicoder_decodeBomFromFile+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <unicoder_decodeBomFromFile+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
lea    -0x24(%rbp),%rdi
call   1060 <unicoder_decodeBom@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicoder_decodeBomFromFile>:
test   %rdi,%rdi
je     11eb <unicoder_decodeBomFromFile+0xab>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %rax,%r14
mov    0x2e75(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
movl   $0x0,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2e61(%rip),%r12
cmp    (%r12),%eax
je     11c7 <unicoder_decodeBomFromFile+0x87>
mov    %al,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     11c7 <unicoder_decodeBomFromFile+0x87>
mov    %al,0x5(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     11c7 <unicoder_decodeBomFromFile+0x87>
mov    %al,0x6(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     11c7 <unicoder_decodeBomFromFile+0x87>
mov    %al,0x7(%rsp)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fseek@plt>
lea    0x4(%rsp),%rdi
call   1060 <unicoder_decodeBom@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0xffffffc0,%eax
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @unicoder_decodeBomFromFile(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca [4 x i8]
store i32* %0, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -64, i32* %2
br label %55
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i64 @ftell(i32* %12)
store i64 %13, i64* %6
%14 = load i32*, i32** %3
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
store i32 0, i32* %4
br label %17
17: ; preds = %24, %11
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %17
27: ; preds = %17
store i32 0, i32* %4
br label %28
28: ; preds = %45, %27
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %48
31: ; preds = %28
%32 = load i32*, i32** %3
%33 = call i32 @fgetc(i32* %32)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %31
br label %48
38: ; preds = %31
%39 = load i32, i32* %5
%40 = trunc i32 %39 to i8
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 %42
store i8 %40, i8* %43
br label %44
44: ; preds = %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %28
48: ; preds = %37, %28
%49 = load i32*, i32** %3
%50 = load i64, i64* %6
%51 = load i32, i32* @SEEK_SET
%52 = call i32 @fseek(i32* %49, i64 %50, i32 %51)
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%54 = call i32 @unicoder_decodeBom(i8* %53)
store i32 %54, i32* %2
br label %55
55: ; preds = %48, %10
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @unicoder_decodeBomFromFile(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to [4 x i8]*
%4 = bitcast i32* %2 to i8*
%5 = icmp eq i32* %0, null
br i1 %5, label %37, label %6
6: ; preds = %1
%7 = tail call i64 @ftell(i32* %0)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %0, i64 0, i32 %8)
store i32 0, i32* %2
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %33, label %13
13: ; preds = %6
%14 = trunc i32 %10 to i8
store i8 %14, i8* %4
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %33, label %18
18: ; preds = %13
%19 = trunc i32 %15 to i8
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 %19, i8* %20
%21 = tail call i32 @fgetc(i32* %0)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %33, label %24
24: ; preds = %18
%25 = trunc i32 %21 to i8
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %25, i8* %26
%27 = tail call i32 @fgetc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = trunc i32 %27 to i8
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 %31, i8* %32
br label %33
33: ; preds = %30, %24, %18, %13, %6
%34 = load i32, i32* @SEEK_SET
%35 = tail call i32 @fseek(i32* %0, i64 %7, i32 %34)
%36 = call i32 @unicoder_decodeBom(i8* %4)
br label %37
37: ; preds = %1, %33
%38 = phi i32 [ %36, %33 ], [ -64, %1 ]
ret i32 %38
}