#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 SEEK_CUR;
int SEEK_END;
int SEEK_SET;
scalar_t__ fseek(int /*<<< orphan*/ *, long, int);
int CPSetFilePosition(FILE *fileRef, long filePos, int mode) {
  int seekMode;
  switch (mode) {
  case -1:
    seekMode = SEEK_SET;
    break;
  case 0:
    seekMode = SEEK_CUR;
    break;
  case 1:
    seekMode = SEEK_END;
    break;
  default:
    return 10005;
  }
  if (fseek(fileRef, filePos, seekMode) != 0)
    return 10005;
  return 0;
}


x86 assembly (clang, -O0):
<CPSetFilePosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xffffffff,%eax
je     1158 <CPSetFilePosition+0x48>
jmp    1137 <CPSetFilePosition+0x27>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     1169 <CPSetFilePosition+0x59>
jmp    1147 <CPSetFilePosition+0x37>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     117a <CPSetFilePosition+0x6a>
jmp    118b <CPSetFilePosition+0x7b>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <CPSetFilePosition+0x87>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <CPSetFilePosition+0x87>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <CPSetFilePosition+0x87>
movl   $0x2715,-0x4(%rbp)
jmp    11c4 <CPSetFilePosition+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <fseek@plt>
cmp    $0x0,%rax
je     11bd <CPSetFilePosition+0xad>
movl   $0x2715,-0x4(%rbp)
jmp    11c4 <CPSetFilePosition+0xb4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CPSetFilePosition>:
add    $0x1,%edx
mov    $0x2715,%eax
cmp    $0x2,%edx
ja     1144 <CPSetFilePosition+0x34>
push   %rax
movslq %edx,%rax
lea    0x2ce0(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    (%rax),%edx
call   1030 <fseek@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x2715,%eax
cmove  %ecx,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
define i32 @CPSetFilePosition(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
switch i32 %9, label %16 [
i32 -1, label %10
i32 0, label %12
i32 1, label %14
]
10: ; preds = %3
%11 = load i32, i32* @SEEK_SET
store i32 %11, i32* %8
br label %17
12: ; preds = %3
%13 = load i32, i32* @SEEK_CUR
store i32 %13, i32* %8
br label %17
14: ; preds = %3
%15 = load i32, i32* @SEEK_END
store i32 %15, i32* %8
br label %17
16: ; preds = %3
store i32 10005, i32* %4
br label %25
17: ; preds = %14, %12, %10
%18 = load i32*, i32** %5
%19 = load i64, i64* %6
%20 = load i32, i32* %8
%21 = call i64 @fseek(i32* %18, i64 %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 10005, i32* %4
br label %25
24: ; preds = %17
store i32 0, i32* %4
br label %25
25: ; preds = %24, %23, %16
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@switch.table.CPSetFilePosition = [3 x i32*] [i32* @SEEK_SET, i32* @SEEK_CUR, i32* @SEEK_END]
define i32 @CPSetFilePosition(i32* nocapture %0, i64 %1, i32 %2) {
%4 = add i32 %2, 1
%5 = icmp ult i32 %4, 3
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.CPSetFilePosition, i64 0, i64 %7
%9 = load i32*, i32** %8
%10 = load i32, i32* %9
%11 = tail call i64 @fseek(i32* %0, i64 %1, i32 %10)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32 0, i32 10005
br label %14
14: ; preds = %3, %6
%15 = phi i32 [ 10005, %3 ], [ %13, %6 ]
ret i32 %15
}