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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int ftruncate(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printAndFail(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void truncateAndCloseChecksumsFile(FILE *checksumsFile,
                                   char *checksumsFilename) {
  uint64_t checksumsFileTruncation = ftell(checksumsFile);
  if (ftruncate(fileno(checksumsFile), checksumsFileTruncation) == -1) {
    printAndFail("Failed to truncate file %s: %s\n", checksumsFilename,
                 strerror(errno));
  }
  fclose(checksumsFile);
}


x86 assembly (clang, -O0):
<truncateAndCloseChecksumsFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    11c0 <truncateAndCloseChecksumsFile+0x60>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe45(%rip),%rdi
call   1050 <printAndFail@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncateAndCloseChecksumsFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    11a6 <truncateAndCloseChecksumsFile+0x46>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <printAndFail@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Failed to truncate file %s: %s\0A\00"
@errno = global i32 0
define void @truncateAndCloseChecksumsFile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = call i32 @ftell(i32* %6)
store i32 %7, i32* %5
%8 = load i32*, i32** %3
%9 = call i32 @fileno(i32* %8)
%10 = load i32, i32* %5
%11 = call i32 @ftruncate(i32 %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @printAndFail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %16)
br label %18
18: ; preds = %13, %2
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Failed to truncate file %s: %s\0A\00"
@errno = global i32 0
define void @truncateAndCloseChecksumsFile(i32* nocapture %0, i8* %1) {
%3 = tail call i32 @ftell(i32* %0)
%4 = tail call i32 @fileno(i32* %0)
%5 = tail call i32 @ftruncate(i32 %4, i32 %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @printAndFail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %9)
br label %11
11: ; preds = %7, %2
%12 = tail call i32 @fclose(i32* %0)
ret void
}