#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int testfseek() {
  FILE *fp;
  if ((fp = fopen("hello", "r+")) == NULL) {
    perror("Open file textfile");
    return 1;
  }
  if (fseek(fp, 10, SEEK_SET) != 0) {
    perror("Seek file textfile");
    return 1;
  }
  fputc('K', fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<testfseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1191 <testfseek+0x41>
lea    0xe89(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <testfseek+0x98>
mov    -0x10(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     11ca <testfseek+0x7a>
lea    0xe63(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <testfseek+0x98>
mov    -0x10(%rbp),%rsi
mov    $0x4b,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testfseek>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <testfseek+0x50>
mov    %rax,%rbx
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fseek@plt>
test   %rax,%rax
jne    11a9 <testfseek+0x59>
mov    $0x4b,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe62(%rip),%rdi
jmp    11b0 <testfseek+0x60>
lea    0xe6c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [19 x i8] c"Open file textfile\00"
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"Seek file textfile\00"
define i32 @testfseek() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %19
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = load i32, i32* @SEEK_SET
%10 = call i64 @fseek(i32* %8, i32 10, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %19
14: ; preds = %7
%15 = load i32*, i32** %2
%16 = call i32 @fputc(i8 signext 75, i32* %15)
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %1
br label %19
19: ; preds = %14, %12, %5
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [19 x i8] c"Open file textfile\00"
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"Seek file textfile\00"
define i32 @testfseek() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %14
5: ; preds = %0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @fseek(i32* %1, i32 10, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %14
11: ; preds = %5
%12 = tail call i32 @fputc(i8 signext 75, i32* %1)
%13 = tail call i32 @fclose(i32* %1)
br label %14
14: ; preds = %11, %9, %3
%15 = phi i32 [ 1, %3 ], [ 1, %9 ], [ 0, %11 ]
ret i32 %15
}