#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 errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int fseek_test(FILE *fp, int off, int whence) {
  int ret, save_errno;
  int passed;
  printf("fseek(): fp=0x%p, off=%d\n", fp, off);
  fflush(NULL);
  passed = handle_zng(ret = fseek(fp, off, whence));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<fseek_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xea0(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <fseek@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0xfffffffe,%eax
je     11f1 <fseek_test+0xb1>
jmp    11b0 <fseek_test+0x70>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     1210 <fseek_test+0xd0>
jmp    11c4 <fseek_test+0x84>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    122a <fseek_test+0xea>
mov    -0x14(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    122a <fseek_test+0xea>
mov    -0x1c(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2dac(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fseek_test>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <fseek@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e4d(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11bc <fseek_test+0x6c>
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
jmp    11dc <fseek_test+0x8c>
cmp    $0xfffffffe,%eax
jne    11cc <fseek_test+0x7c>
lea    0xe5e(%rip),%rdi
mov    %ebx,%esi
jmp    11d5 <fseek_test+0x85>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"fseek(): fp=0x%p, off=%d\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.4 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @fseek_test(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* %10, i32 %11)
%13 = call i32 @fflush(i32* null)
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @fseek(i32* %14, i32 %15, i32 %16)
store i32 %17, i32* %7
%18 = call i32 @handle_zng(i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* @errno
store i32 %19, i32* %8
%20 = load i32, i32* %9
switch i32 %20, label %30 [
i32 -1, label %21
i32 0, label %21
i32 -2, label %26
]
21: ; preds = %3, %3
%22 = load i32, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @fflush(i32* null)
br label %34
26: ; preds = %3
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = call i32 @fflush(i32* null)
br label %34
30: ; preds = %3
%31 = load i32, i32* %9
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 @fflush(i32* null)
br label %34
34: ; preds = %30, %26, %21
%35 = load i32, i32* %8
store i32 %35, i32* @errno
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [26 x i8] c"fseek(): fp=0x%p, off=%d\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.4 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @fseek_test(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* %0, i32 %1)
%5 = tail call i32 @fflush(i32* null)
%6 = tail call i32 @fseek(i32* %0, i32 %1, i32 %2)
%7 = tail call i32 @handle_zng(i32 %6)
%8 = load i32, i32* @errno
switch i32 %7, label %14 [
i32 -1, label %9
i32 0, label %9
i32 -2, label %12
]
9: ; preds = %3, %3
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %6)
br label %16
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %7)
br label %16
16: ; preds = %14, %12, %9
%17 = tail call i32 @fflush(i32* null)
store i32 %8, i32* @errno
ret i32 %6
}