#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ errno;
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printAndFail(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void updateMD4InChecksumsFile(char *readingMD4, FILE *checksumsFile,
                              int doReplaceLastChecksumOrAdd) {
  char writeMD4[34];
  sprintf(writeMD4, "%s\n", readingMD4);
  if (doReplaceLastChecksumOrAdd == 1) {
    if (fseeko(checksumsFile, -33, SEEK_CUR) == -1) {
      printAndFail("Failed to seek on file: %s\n", strerror(errno));
    }
  }
  if (fputs(writeMD4, checksumsFile) == EOF) {
    printAndFail("Failed to write to file: %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<updateMD4InChecksumsFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea6(%rip),%rsi
call   1060 <sprintf@plt>
cmpl   $0x1,-0x14(%rbp)
jne    11c2 <updateMD4InChecksumsFile+0x72>
mov    -0x10(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffdf,%esi
call   1050 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    11bd <updateMD4InChecksumsFile+0x6d>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe48(%rip),%rdi
call   1040 <printAndFail@plt>
jmp    11c2 <updateMD4InChecksumsFile+0x72>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
jne    11fb <updateMD4InChecksumsFile+0xab>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe26(%rip),%rdi
call   1040 <printAndFail@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateMD4InChecksumsFile>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rdx
lea    0xeb3(%rip),%rsi
mov    %rsp,%rdi
call   1060 <sprintf@plt>
cmp    $0x1,%ebp
jne    11a9 <updateMD4InChecksumsFile+0x59>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffdf,%esi
call   1050 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    11a9 <updateMD4InChecksumsFile+0x59>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
call   1040 <printAndFail@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <fputs@plt>
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
jne    11e2 <updateMD4InChecksumsFile+0x92>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printAndFail@plt>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@SEEK_CUR = global i32 0
@.str.1 = [28 x i8] c"Failed to seek on file: %s\0A\00"
@errno = global i32 0
@EOF = global i64 0
@.str.2 = [29 x i8] c"Failed to write to file: %s\0A\00"
define void @updateMD4InChecksumsFile(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [34 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [34 x i8], [34 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load i32*, i32** %5
%15 = load i32, i32* @SEEK_CUR
%16 = call i32 @fseeko(i32* %14, i32 -33, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @printAndFail(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %13
br label %23
23: ; preds = %22, %3
%24 = getelementptr inbounds [34 x i8], [34 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %5
%26 = call i64 @fputs(i8* %24, i32* %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 @printAndFail(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %23
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@SEEK_CUR = global i32 0
@.str.1 = [28 x i8] c"Failed to seek on file: %s\0A\00"
@errno = global i32 0
@EOF = global i64 0
@.str.2 = [29 x i8] c"Failed to write to file: %s\0A\00"
define void @updateMD4InChecksumsFile(i8* %0, i32* nocapture %1, i32 %2) {
%4 = alloca [34 x i8]
%5 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp eq i32 %2, 1
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = load i32, i32* @SEEK_CUR
%10 = tail call i32 @fseeko(i32* %1, i32 -33, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @printAndFail(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %8, %12, %3
%17 = call i64 @fputs(i8* %5, i32* %1)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = tail call i32 @strerror(i32 %21)
%23 = tail call i32 @printAndFail(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20, %16
ret void
}