#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int main() {
  FILE *f = fopen("testdisk.bin", "w");
  if (f == NULL) {
    printf("could not open file, err: %s", strerror(errno));
    return 1;
  }
  fprintf(f, "hello, world, from disk!\n");
  fputc(0, f);
  fseek(f, 0xFF00, SEEK_SET);
  fprintf(f, "hello from a seeked position.\n");
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <main+0x5a>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <main+0xac>
mov    -0x10(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    $0xff00,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe86(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ec <main+0x7c>
mov    %rax,%rbx
lea    0xe97(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff00,%esi
call   1060 <fseek@plt>
lea    0xe76(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    120e <main+0x9e>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe0e(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"testdisk.bin\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"could not open file, err: %s\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"hello, world, from disk!\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [31 x i8] c"hello from a seeked position.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %8)
store i32 1, i32* %1
br label %22
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32*, i32** %2
%14 = call i32 @fputc(i32 0, i32* %13)
%15 = load i32*, i32** %2
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %15, i32 65280, i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %1
br label %22
22: ; preds = %10, %6
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [13 x i8] c"testdisk.bin\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"could not open file, err: %s\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"hello, world, from disk!\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [31 x i8] c"hello from a seeked position.\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 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 %7
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i8* @strerror(i32 %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %14
7: ; preds = %0
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 25, i64 1, i32* %1)
%9 = tail call i32 @fputc(i32 0, i32* %1)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %1, i32 65280, i32 %10)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 30, i64 1, i32* %1)
%13 = tail call i32 @fclose(i32* %1)
br label %14
14: ; preds = %7, %3
%15 = phi i32 [ 1, %3 ], [ 0, %7 ]
ret i32 %15
}