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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char const *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, char const *);
FILE *open_and_seek(const char *filename, const char *mode, off_t offset) {
  FILE *f;
  f = fopen(filename, mode);
  if (f == NULL) {
    perror("fopen()");
    printf("%s:%d filename = %s\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/niven/connect4/refs/heads/master/utils.c",
           58, filename);
    exit(EXIT_FAILURE);
  };
  if (fseek(f, offset, SEEK_SET)) {
    perror("fseek()");
    return NULL;
  }
  return f;
}


x86 assembly (clang, -O0):
<open_and_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b5 <open_and_seek+0x65>
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rcx
lea    0xe72(%rip),%rdi
lea    0xe80(%rip),%rsi
mov    $0x3a,%edx
call   1030 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     11ed <open_and_seek+0x9d>
lea    0xec5(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <open_and_seek+0xa5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_and_seek>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
call   1050 <fopen@plt>
test   %rax,%rax
je     1196 <open_and_seek+0x46>
mov    %rax,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <fseek@plt>
test   %rax,%rax
jne    1186 <open_and_seek+0x36>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xf13(%rip),%rdi
call   1060 <perror@plt>
xor    %ebx,%ebx
jmp    117e <open_and_seek+0x2e>
lea    0xe63(%rip),%rdi
call   1060 <perror@plt>
lea    0xe5f(%rip),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x3a,%edx
mov    %r14,%rcx
call   1030 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"fopen()\00"
@.str.1 = [21 x i8] c"%s:%d filename = %s\0A\00"
@.str.2 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/niven/connect4/refs/heads/master/utils.c\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [8 x i8] c"fseek()\00"
define i32* @open_and_seek(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %9, i8* %10)
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %5
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 58, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %3
%21 = load i32*, i32** %8
%22 = load i32, i32* %7
%23 = load i32, i32* @SEEK_SET
%24 = call i64 @fseek(i32* %21, i32 %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32* null, i32** %4
br label %30
28: ; preds = %20
%29 = load i32*, i32** %8
store i32* %29, i32** %4
br label %30
30: ; preds = %28, %26
%31 = load i32*, i32** %4
ret i32* %31
}

LLVM IR (-O2):
@.str = [8 x i8] c"fopen()\00"
@.str.1 = [21 x i8] c"%s:%d filename = %s\0A\00"
@.str.2 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/niven/connect4/refs/heads/master/utils.c\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [8 x i8] c"fseek()\00"
define noalias i32* @open_and_seek(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 58, i8* %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
%12 = load i32, i32* @SEEK_SET
%13 = tail call i64 @fseek(i32* %4, i32 %2, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %11, %15
%18 = phi i32* [ null, %15 ], [ %4, %11 ]
ret i32* %18
}