#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 */
char EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  char *filename = "fox.txt";
  FILE *fp = fopen(filename, "r");
  char c = 0;
  if (fp) {
    fseek(fp, 5, SEEK_SET);
    while ((c = fgetc(fp)) != EOF) {
      printf("%c", c);
    }
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fa <main+0x9a>
mov    -0x18(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e1e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ec <main+0x8c>
movsbl -0x19(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b4 <main+0x54>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    120c <main+0xac>
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cf <main+0x6f>
mov    %rax,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e44(%rip),%r14
cmp    (%r14),%al
je     11c5 <main+0x65>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    11b0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11e4 <main+0x84>
lea    0xe34(%rip),%rdi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"fox.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i8 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
store i32 0, i32* %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
store i8 0, i8* %4
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %27
9: ; preds = %0
%10 = load i32*, i32** %3
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %10, i32 5, i32 %11)
br label %13
13: ; preds = %20, %9
%14 = load i32*, i32** %3
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %4
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %13
24: ; preds = %13
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
br label %30
27: ; preds = %0
%28 = load i8*, i8** %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %24
%31 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"fox.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i8 0
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %18, label %3
3: ; preds = %0
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %1, i32 5, i32 %4)
%6 = tail call signext i8 @fgetc(i32* %1)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %16, label %9
9: ; preds = %3, %9
%10 = phi i8 [ %13, %9 ], [ %6, %3 ]
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call signext i8 @fgetc(i32* %1)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %9
16: ; preds = %9, %3
%17 = tail call i32 @fclose(i32* %1)
br label %20
18: ; preds = %0
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = tail call i32 @putchar(i32 10)
ret i32 0
}