#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_SET;
int fseek(int /*<<< orphan*/ *, long, int);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, long, int);
int myfseek(FILE *stream, long int offset, int origin) {
  int i;
  i = fseek(stream, offset, origin);
  if (i != 0 && origin == SEEK_CUR) {
    i = fseek(stream, ftell(stream) + offset, SEEK_SET);
    if (i != 0)
      printf("myfseek: ftell=%i, orig=%i, offset=%i, ret=%i\n", ftell(stream),
             origin, offset, i);
  }
  return i;
}


x86 assembly (clang, -O0):
<myfseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <fseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11d0 <myfseek+0xa0>
mov    -0x14(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    11d0 <myfseek+0xa0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    -0x20(%rbp),%rdi
movslq %eax,%rsi
add    -0x10(%rbp),%rsi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11cb <myfseek+0x9b>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8d
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <myfseek+0xa0>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myfseek>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <fseek@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     11a6 <myfseek+0x76>
mov    0x2e95(%rip),%rdx
mov    %ecx,%eax
cmp    %ebp,(%rdx)
jne    11a6 <myfseek+0x76>
mov    %rbx,%rdi
call   1040 <ftell@plt>
movslq %eax,%rsi
add    %r14,%rsi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1050 <fseek@plt>
mov    %eax,%r15d
mov    $0x0,%eax
test   %r15d,%r15d
je     11a6 <myfseek+0x76>
mov    %rbx,%rdi
call   1040 <ftell@plt>
lea    0xe6c(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %r15d,%r8d
call   1030 <printf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str = [47 x i8] c"myfseek: ftell=%i, orig=%i, offset=%i, ret=%i\0A\00"
define i32 @myfseek(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = load i64, i64* %5
%10 = load i32, i32* %6
%11 = call i32 @fseek(i32* %8, i64 %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %3
%15 = load i32, i32* %6
%16 = load i32, i32* @SEEK_CUR
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32*, i32** %4
%21 = call i32 @ftell(i32* %20)
%22 = sext i32 %21 to i64
%23 = load i64, i64* %5
%24 = add nsw i64 %22, %23
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %19, i64 %24, i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %18
%30 = load i32*, i32** %4
%31 = call i32 @ftell(i32* %30)
%32 = load i32, i32* %6
%33 = load i64, i64* %5
%34 = load i32, i32* %7
%35 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32, i64 %33, i32 %34)
br label %36
36: ; preds = %29, %18
br label %37
37: ; preds = %36, %14, %3
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str = [47 x i8] c"myfseek: ftell=%i, orig=%i, offset=%i, ret=%i\0A\00"
define i32 @myfseek(i32* nocapture %0, i64 %1, i32 %2) {
%4 = tail call i32 @fseek(i32* %0, i64 %1, i32 %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_CUR
%8 = icmp eq i32 %7, %2
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i32 @ftell(i32* %0)
%11 = sext i32 %10 to i64
%12 = add nsw i64 %11, %1
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %0, i64 %12, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = tail call i32 @ftell(i32* %0)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %2, i64 %1, i32 %14)
br label %19
19: ; preds = %9, %16, %6, %3
%20 = phi i32 [ %14, %16 ], [ 0, %9 ], [ %4, %6 ], [ 0, %3 ]
ret i32 %20
}