#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;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, char const *, int /*<<< orphan*/);
int ftruncate(int, int /*<<< orphan*/);
char *name_get(unsigned int);
int /*<<< orphan*/ printf(char *, char const *, int /*<<< orphan*/);
void do_truncate(int fd, unsigned name, off_t len) {
  const char *namestr;
  namestr = name_get(name);
  if (ftruncate(fd, len) == -1) {
    err(1, "%s: truncate to %lld", namestr, len);
  }
  printf("truncate %s: to %lld\n", namestr, len);
}


x86 assembly (clang, -O0):
<do_truncate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <name_get@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    1189 <do_truncate+0x49>
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x1,%edi
lea    0xe7c(%rip),%rsi
call   1050 <err@plt>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_truncate>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %edi,%ebp
mov    %esi,%edi
call   1060 <name_get@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    1176 <do_truncate+0x36>
lea    0xe99(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1050 <err@plt>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"%s: truncate to %lld\00"
@.str.1 = [22 x i8] c"truncate %s: to %lld\0A\00"
define void @do_truncate(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = call i8* @name_get(i32 %8)
store i8* %9, i8** %7
%10 = load i32, i32* %4
%11 = load i32, i32* %6
%12 = call i32 @ftruncate(i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load i32, i32* %6
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
br label %18
18: ; preds = %14, %3
%19 = load i8*, i8** %7
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s: truncate to %lld\00"
@.str.1 = [22 x i8] c"truncate %s: to %lld\0A\00"
define void @do_truncate(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @name_get(i32 %1)
%5 = tail call i32 @ftruncate(i32 %0, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %2)
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %2)
ret void
}