#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*/ offset;
typedef int /*<<< orphan*/ fpos_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fgetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fsetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int opener(FILE *file) {
  int rc;
  fpos_t offset;
  memset(&offset, 3, sizeof(offset));
  if (file == NULL) {
    return -1;
  }
  rc = fgetpos(file, &offset);
  if (rc != 0) {
    return rc;
  }
  char *buffer = malloc(10);
  int x = fread(buffer, 1, 10, file);
  if (x == 0) {
    printf("Fread failed\n");
    exit(0);
  } else {
    printf("Buffer content is: %s\n", buffer);
  }
  rc = fsetpos(file, &offset);
  if (rc != 0) {
    printf("Fsetpos fails\n");
    return rc;
  } else {
    printf("File position is %d\n", rc);
  }
  return 0;
}


x86 assembly (clang, -O0):
<opener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <opener+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <opener+0xff>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <fgetpos@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cb <opener+0x5b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126f <opener+0xff>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1212 <opener+0xa2>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <fsetpos@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1257 <opener+0xe7>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126f <opener+0xff>
mov    -0x14(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opener>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
test   %rbx,%rbx
je     1213 <opener+0x93>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <fgetpos@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1218 <opener+0x98>
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1235 <opener+0xb5>
lea    0xe1c(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <fsetpos@plt>
test   %eax,%eax
je     1223 <opener+0xa3>
mov    %eax,%ebx
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%ebp
jmp    1218 <opener+0x98>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xded(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1218 <opener+0x98>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Fread failed\0A\00"
@.str.1 = [23 x i8] c"Buffer content is: %s\0A\00"
@.str.2 = [15 x i8] c"Fsetpos fails\0A\00"
@.str.3 = [21 x i8] c"File position is %d\0A\00"
define i32 @opener(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %3
%8 = call i32 @memset(i32* %5, i32 3, i32 4)
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %44
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @fgetpos(i32* %13, i32* %5)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %44
19: ; preds = %12
%20 = call i8* @malloc(i32 10)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i32*, i32** %3
%23 = call i32 @fread(i8* %21, i32 1, i32 10, i32* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %19
%30 = load i8*, i8** %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29
%33 = load i32*, i32** %3
%34 = call i32 @fsetpos(i32* %33, i32* %5)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %4
store i32 %39, i32* %2
br label %44
40: ; preds = %32
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40
store i32 0, i32* %2
br label %44
44: ; preds = %43, %37, %17, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Buffer content is: %s\0A\00"
@.str.3 = [21 x i8] c"File position is %d\0A\00"
@str = [14 x i8] c"Fsetpos fails\00"
@str.4 = [13 x i8] c"Fread failed\00"
define i32 @opener(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @memset(i32* %2, i32 3, i32 4)
%5 = icmp eq i32* %0, null
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = call i32 @fgetpos(i32* %0, i32* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = call dereferenceable_or_null(10) i8* @malloc(i32 10)
%11 = call i32 @fread(i8* %10, i32 1, i32 10, i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %9
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%18 = call i32 @fsetpos(i32* %0, i32* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %24
24: ; preds = %20, %22, %6, %1
%25 = phi i32 [ -1, %1 ], [ %7, %6 ], [ %18, %20 ], [ 0, %22 ]
ret i32 %25
}