#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 */
scalar_t__ SEEK_SET;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fseek(int /*<<< orphan*/ *, unsigned int, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main(int argc, char *argv[]) {
  FILE *f = fopen(argv[0], "rb");
  if (!f) {
    printf("Error: Can't open %s, reason: %s\n", argv[0], strerror(errno));
    return 1;
  }
  if (fseek(f, (unsigned)4096, (int)SEEK_SET) == -1) {
    printf("Test failed, fseek return fail code. errno=%u (%s)\n", errno,
           strerror(errno));
    return 1;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <main+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x18(%rbp),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
mov    $0x1000,%esi
call   1050 <fseek@plt>
cmp    $0xffffffff,%eax
jne    121f <main+0xcf>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rsi),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1195 <main+0x45>
mov    %rax,%rbx
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <fseek@plt>
cmp    $0xffffffff,%eax
je     11bc <main+0x6c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11e4 <main+0x94>
mov    (%r14),%rbx
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe56(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11df <main+0x8f>
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe52(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [34 x i8] c"Error: Can't open %s, reason: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i64 0
@.str.2 = [52 x i8] c"Test failed, fseek return fail code. errno=%u (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
store i32 1, i32* %3
br label %34
20: ; preds = %2
%21 = load i32*, i32** %6
%22 = load i64, i64* @SEEK_SET
%23 = trunc i64 %22 to i32
%24 = call i32 @fseek(i32* %21, i32 4096, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* @errno
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %27, i8* %29)
store i32 1, i32* %3
br label %34
31: ; preds = %20
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %3
br label %34
34: ; preds = %31, %26, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [34 x i8] c"Error: Can't open %s, reason: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i64 0
@.str.2 = [52 x i8] c"Test failed, fseek return fail code. errno=%u (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %9)
br label %22
11: ; preds = %2
%12 = load i64, i64* @SEEK_SET
%13 = trunc i64 %12 to i32
%14 = tail call i32 @fseek(i32* %4, i32 4096, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %17, i8* %18)
br label %22
20: ; preds = %11
%21 = tail call i32 @fclose(i32* %4)
br label %22
22: ; preds = %20, %16, %6
%23 = phi i32 [ 1, %16 ], [ 0, %20 ], [ 1, %6 ]
ret i32 %23
}