#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fseeko(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printAndFail(char *);
void changeByte(char *filename, off_t position, char byte) {
  FILE *f = fopen(filename, "r+");
  if (!f) {
    printAndFail("Cannot create file");
  }
  if (fseeko(f, position, SEEK_SET) < 0) {
    printAndFail("Cannot seek");
  }
  char bytes[1];
  bytes[0] = byte;
  if (fwrite(bytes, 1, 1, f) != 1) {
    printAndFail("Cannot write data 2");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<changeByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <changeByte+0x3f>
lea    0xe79(%rip),%rdi
call   1040 <printAndFail@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1050 <fseeko@plt>
cmp    $0x0,%rax
jge    11ba <changeByte+0x6a>
lea    0xe61(%rip),%rdi
call   1040 <printAndFail@plt>
mov    -0xd(%rbp),%al
mov    %al,-0x19(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     11e9 <changeByte+0x99>
lea    0xe3e(%rip),%rdi
call   1040 <printAndFail@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeByte>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <changeByte+0x2d>
lea    0xe8b(%rip),%rdi
call   1040 <printAndFail@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fseeko@plt>
test   %rax,%rax
jns    11a1 <changeByte+0x51>
lea    0xe7a(%rip),%rdi
call   1040 <printAndFail@plt>
mov    %r14b,0xf(%rsp)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     11ce <changeByte+0x7e>
lea    0xe59(%rip),%rdi
call   1040 <printAndFail@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@SEEK_SET = global i32 0
@.str.2 = [12 x i8] c"Cannot seek\00"
@.str.3 = [20 x i8] c"Cannot write data 2\00"
define void @changeByte(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
%8 = alloca [1 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i32*, i32** %7
%17 = load i32, i32* %5
%18 = load i32, i32* @SEEK_SET
%19 = call i64 @fseeko(i32* %16, i32 %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printAndFail(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
%24 = load i8, i8* %6
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
store i8 %24, i8* %25
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %7
%28 = call i32 @fwrite(i8* %26, i32 1, i32 1, i32* %27)
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %23
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@SEEK_SET = global i32 0
@.str.2 = [12 x i8] c"Cannot seek\00"
@.str.3 = [20 x i8] c"Cannot write data 2\00"
define void @changeByte(i8* nocapture %0, i32 %1, i8 signext %2) {
%4 = alloca [1 x i8]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = load i32, i32* @SEEK_SET
%11 = tail call i64 @fseeko(i32* %5, i32 %1, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @printAndFail(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
store i8 %2, i8* %16
%17 = call i32 @fwrite(i8* %16, i32 1, i32 1, i32* %5)
%18 = icmp eq i32 %17, 1
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = tail call i32 @fclose(i32* %5)
ret void
}