#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *f_in;
  int floc;
  f_in = fopen("x_data.in", "r");
  if (!f_in) {
    printf("cannot open file \"x_data.in\"\n");
  } else {
    printf("about to call ftell()\n");
    floc = ftell(f_in);
    if (floc != 0) {
      printf("ftell fails, return value = %d, error = %d\n", floc, errno);
      exit(1);
    } else {
      printf("ftell succeeds, return value = %d\n", floc);
    }
    if (fseek(f_in, 4L, SEEK_SET) < 0) {
      printf("fseek fails, return value = %d, error = %d\n", floc, errno);
      exit(1);
    }
    floc = ftell(f_in);
    if (floc != 4) {
      printf("ftell fails, return value = %d, error = %d\n", floc, errno);
      exit(1);
    } else {
      printf("ftell succeeds, return value = %d\n", floc);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <main+0x44>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1282 <main+0x132>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11dc <main+0x8c>
mov    -0x14(%rbp),%esi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
jge    1232 <main+0xe2>
mov    -0x14(%rbp),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
je     126c <main+0x11c>
mov    -0x14(%rbp),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1282 <main+0x132>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    118c <main+0x2c>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %rax,%rbx
lea    0xf0e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
test   %eax,%eax
jne    120d <main+0xad>
lea    0xe8a(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
mov    %rbx,%rdi
call   1060 <fseek@plt>
test   %rax,%rax
jns    11e6 <main+0x86>
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rdi
xor    %esi,%esi
jmp    121f <main+0xbf>
mov    %rbx,%rdi
call   1050 <ftell@plt>
cmp    $0x4,%eax
jne    120d <main+0xad>
lea    0xe3e(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2dcc(%rip),%rcx
mov    (%rcx),%edx
lea    0xdef(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"x_data.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"cannot open file \22x_data.in\22\0A\00"
@.str.3 = [23 x i8] c"about to call ftell()\0A\00"
@.str.4 = [44 x i8] c"ftell fails, return value = %d, error = %d\0A\00"
@errno = global i32 0
@.str.5 = [35 x i8] c"ftell succeeds, return value = %d\0A\00"
@SEEK_SET = global i32 0
@.str.6 = [44 x i8] c"fseek fails, return value = %d, error = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %47
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%11 = load i32*, i32** %2
%12 = call i32 @ftell(i32* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i32, i32* %3
%17 = load i32, i32* @errno
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %9
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20
%24 = load i32*, i32** %2
%25 = load i32, i32* @SEEK_SET
%26 = call i64 @fseek(i32* %24, i64 4, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32, i32* %3
%30 = load i32, i32* @errno
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = load i32*, i32** %2
%35 = call i32 @ftell(i32* %34)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = icmp ne i32 %36, 4
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* %3
%40 = load i32, i32* @errno
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43
br label %47
47: ; preds = %46, %7
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"x_data.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [44 x i8] c"ftell fails, return value = %d, error = %d\0A\00"
@errno = global i32 0
@.str.5 = [35 x i8] c"ftell succeeds, return value = %d\0A\00"
@SEEK_SET = global i32 0
@.str.6 = [44 x i8] c"fseek fails, return value = %d, error = %d\0A\00"
@str = [29 x i8] c"cannot open file \22x_data.in\22\00"
@str.7 = [22 x i8] c"about to call ftell()\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %31
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 @ftell(i32* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = load i32, i32* @errno
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %7, i32 %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 0)
%15 = load i32, i32* @SEEK_SET
%16 = tail call i64 @fseek(i32* %1, i64 4, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 0, i32 %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = tail call i32 @ftell(i32* %1)
%24 = icmp eq i32 %23, 4
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 4)
br label %31
31: ; preds = %29, %3
%32 = tail call i32 @exit(i32 0)
unreachable
}