#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int close(int);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void fileSeek(char *fname) {
  int fd;
  off_t ret;
  int pos = 217;
  fd = open(fname, O_RDONLY);
  if (fd == -1) {
    printf("Error opening file\n");
    return;
  }
  ret = lseek(fd, (off_t)pos, SEEK_SET);
  if (ret == (off_t)-1) {
    printf("Error setting file pos\n");
  } else {
    printf("Set position  %zu\n", ret);
  }
  if (close(fd) == -1) {
    printf("Error closing file\n");
  }
}


x86 assembly (clang, -O0):
<fileSeek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xd9,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1185 <fileSeek+0x45>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <fileSeek+0xad>
mov    -0xc(%rbp),%edi
movslq -0x1c(%rbp),%rsi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11bc <fileSeek+0x7c>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ce <fileSeek+0x8e>
mov    -0x18(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    11ed <fileSeek+0xad>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileSeek>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1194 <fileSeek+0x44>
mov    %eax,%ebx
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    $0xd9,%esi
mov    %ebx,%edi
call   1050 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     11a1 <fileSeek+0x51>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ad <fileSeek+0x5d>
lea    0xea2(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
je     11bb <fileSeek+0x6b>
pop    %rbx
ret
lea    0xe51(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [20 x i8] c"Error opening file\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [24 x i8] c"Error setting file pos\0A\00"
@.str.2 = [19 x i8] c"Set position %zu\0A\00"
@.str.3 = [20 x i8] c"Error closing file\0A\00"
define void @fileSeek(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
store i32 217, i32* %5
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %32
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = load i32, i32* @SEEK_SET
%18 = call i64 @lseek(i32 %14, i64 %16, i32 %17)
store i64 %18, i64* %4
%19 = load i64, i64* %4
%20 = icmp eq i64 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %26
23: ; preds = %13
%24 = load i64, i64* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %23, %21
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %11, %30, %26
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [19 x i8] c"Set position %zu\0A\00"
@str = [19 x i8] c"Error closing file\00"
@str.4 = [23 x i8] c"Error setting file pos\00"
@str.5 = [19 x i8] c"Error opening file\00"
define void @fileSeek(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %3, i64 217, i32 %6)
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %13
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %7)
br label %13
13: ; preds = %11, %9
%14 = tail call i32 @close(i32 %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13, %1
%17 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0), %1 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %13 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
br label %19
19: ; preds = %16, %13
ret void
}