#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_readCodePoint(unsigned char *, unsigned int *, unsigned int);
int unicoder_readCodePointFromFile(FILE *f, unsigned int *result,
                                   unsigned int encoding) {
  int i, currChar, bytesRead;
  long originalPosition;
  unsigned char bytes[6];
  if (f == NULL)
    return -64;
  originalPosition = ftell(f);
  for (i = 0; i < 6; i++)
    bytes[i] = 0;
  for (i = 0; i < 6; i++) {
    currChar = fgetc(f);
    if (currChar == EOF)
      break;
    else
      bytes[i] = (unsigned char)currChar;
  }
  bytesRead = unicoder_readCodePoint(bytes, result, encoding);
  if (bytesRead >= 0)
    fseek(f, originalPosition + bytesRead, SEEK_SET);
  else
    fseek(f, originalPosition, SEEK_SET);
  if ((*result) == 0x0000feff)
    return unicoder_readCodePointFromFile(f, result, encoding);
  return bytesRead;
}


x86 assembly (clang, -O0):
<unicoder_readCodePointFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <unicoder_readCodePointFromFile+0x2a>
movl   $0xffffffc0,-0x4(%rbp)
jmp    1286 <unicoder_readCodePointFromFile+0x136>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
jge    11af <unicoder_readCodePointFromFile+0x5f>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x36(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118e <unicoder_readCodePointFromFile+0x3e>
movl   $0x0,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
jge    1203 <unicoder_readCodePointFromFile+0xb3>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%eax
jne    11e3 <unicoder_readCodePointFromFile+0x93>
jmp    1203 <unicoder_readCodePointFromFile+0xb3>
mov    -0x24(%rbp),%eax
mov    %al,%cl
movslq -0x20(%rbp),%rax
mov    %cl,-0x36(%rbp,%rax,1)
jmp    11f5 <unicoder_readCodePointFromFile+0xa5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b6 <unicoder_readCodePointFromFile+0x66>
lea    -0x36(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <unicoder_readCodePoint@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1242 <unicoder_readCodePointFromFile+0xf2>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
jmp    1258 <unicoder_readCodePointFromFile+0x108>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
cmpl   $0xfeff,(%rax)
jne    1280 <unicoder_readCodePointFromFile+0x130>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <unicoder_readCodePointFromFile@plt>
mov    %eax,-0x4(%rbp)
jmp    1286 <unicoder_readCodePointFromFile+0x136>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicoder_readCodePointFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1237 <unicoder_readCodePointFromFile+0xe7>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1060 <ftell@plt>
mov    %rax,%r12
movl   $0x0,0x8(%rsp)
movw   $0x0,0xc(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    0x2e54(%rip),%rbx
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0x8(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0x9(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0xa(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0xb(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0xc(%rsp)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%rbx),%eax
je     11ec <unicoder_readCodePointFromFile+0x9c>
mov    %al,0xd(%rsp)
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <unicoder_readCodePoint@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
cmovns %ebx,%eax
add    %rax,%r12
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <fseek@plt>
cmpl   $0xfeff,(%r15)
jne    123c <unicoder_readCodePointFromFile+0xec>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <unicoder_readCodePointFromFile@plt>
mov    %eax,%ebx
jmp    123c <unicoder_readCodePointFromFile+0xec>
mov    $0xffffffc0,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@SEEK_SET = global i32 0
define i32 @unicoder_readCodePointFromFile(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca [6 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -64, i32* %4
br label %81
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %11
store i32 0, i32* %8
br label %19
19: ; preds = %26, %16
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 6
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %22
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %19
29: ; preds = %19
store i32 0, i32* %8
br label %30
30: ; preds = %47, %29
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 6
br i1 %32, label %33, label %50
33: ; preds = %30
%34 = load i32*, i32** %5
%35 = call i32 @fgetc(i32* %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %33
br label %50
40: ; preds = %33
%41 = load i32, i32* %9
%42 = trunc i32 %41 to i8
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %40
br label %47
47: ; preds = %46
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %30
50: ; preds = %39, %30
%51 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%52 = load i32*, i32** %6
%53 = load i32, i32* %7
%54 = call i32 @unicoder_readCodePoint(i8* %51, i32* %52, i32 %53)
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = icmp sge i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %50
%58 = load i32*, i32** %5
%59 = load i64, i64* %11
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = add nsw i64 %59, %61
%63 = load i32, i32* @SEEK_SET
%64 = call i32 @fseek(i32* %58, i64 %62, i32 %63)
br label %70
65: ; preds = %50
%66 = load i32*, i32** %5
%67 = load i64, i64* %11
%68 = load i32, i32* @SEEK_SET
%69 = call i32 @fseek(i32* %66, i64 %67, i32 %68)
br label %70
70: ; preds = %65, %57
%71 = load i32*, i32** %6
%72 = load i32, i32* %71
%73 = icmp eq i32 %72, 65279
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = load i32*, i32** %5
%76 = load i32*, i32** %6
%77 = load i32, i32* %7
%78 = call i32 @unicoder_readCodePointFromFile(i32* %75, i32* %76, i32 %77)
store i32 %78, i32* %4
br label %81
79: ; preds = %70
%80 = load i32, i32* %10
store i32 %80, i32* %4
br label %81
81: ; preds = %79, %74, %15
%82 = load i32, i32* %4
ret i32 %82
}

LLVM IR (-O2):
@EOF = global i32 0
@SEEK_SET = global i32 0
define i32 @unicoder_readCodePointFromFile(i32* %0, i32* %1, i32 %2) {
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32* %0, null
br i1 %6, label %57, label %7
7: ; preds = %3
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = tail call i64 @ftell(i32* %0)
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %45, label %13
13: ; preds = %7
%14 = trunc i32 %10 to i8
store i8 %14, i8* %5
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %45, label %18
18: ; preds = %13
%19 = trunc i32 %15 to i8
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %4, 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 %45, label %24
24: ; preds = %18
%25 = trunc i32 %21 to i8
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %4, 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 %45, label %30
30: ; preds = %24
%31 = trunc i32 %27 to i8
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
store i8 %31, i8* %32
%33 = tail call i32 @fgetc(i32* %0)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %45, label %36
36: ; preds = %30
%37 = trunc i32 %33 to i8
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
store i8 %37, i8* %38
%39 = tail call i32 @fgetc(i32* %0)
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %45, label %42
42: ; preds = %36
%43 = trunc i32 %39 to i8
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
store i8 %43, i8* %44
br label %45
45: ; preds = %42, %36, %30, %24, %18, %13, %7
%46 = call i32 @unicoder_readCodePoint(i8* %5, i32* %1, i32 %2)
%47 = icmp sgt i32 %46, 0
%48 = select i1 %47, i32 %46, i32 0
%49 = zext i32 %48 to i64
%50 = add nsw i64 %9, %49
%51 = load i32, i32* @SEEK_SET
%52 = call i32 @fseek(i32* %0, i64 %50, i32 %51)
%53 = load i32, i32* %1
%54 = icmp eq i32 %53, 65279
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = call i32 @unicoder_readCodePointFromFile(i32* %0, i32* %1, i32 %2)
br label %57
57: ; preds = %45, %3, %55
%58 = phi i32 [ %56, %55 ], [ -64, %3 ], [ %46, %45 ]
ret i32 %58
}