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

/* Variables and functions */
scalar_t__ atoll(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *,
                           unsigned long long, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int truncate64(char *, scalar_t__);
int main(int argc, char **argv) {
  loff_t newsize = 0;
  char *filename;
  if (argc < 3) {
    printf("Usage: %s <path> <size>\n", argv[0]);
    printf("  size is expected to be in bytes\n");
    return 1;
  }
  filename = argv[1];
  newsize = atoll(argv[2]);
  printf("Truncating %s to %lld\n", filename, (unsigned long long)newsize);
  if (truncate64(filename, newsize) == -1) {
    fprintf(stderr, "Could not truncate %s to %lld bytes: %s\n", filename,
            (unsigned long long)newsize, strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a7 <main+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <main+0xf7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atoll@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <truncate64@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xf0>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %eax,%r8d
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <main+0xf7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     1188 <main+0x28>
mov    (%rsi),%rsi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
jmp    11ec <main+0x8c>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   1050 <atoll@plt>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <truncate64@plt>
cmp    $0xffffffff,%eax
jne    11f1 <main+0x91>
mov    0x2e1b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe54(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1060 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: %s <path> <size>\0A\00"
@.str.1 = [35 x i8] c" size is expected to be in bytes\0A\00"
@.str.2 = [23 x i8] c"Truncating %s to %lld\0A\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Could not truncate %s to %lld bytes: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %39
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @atoll(i8* %22)
store i64 %23, i64* %6
%24 = load i8*, i8** %7
%25 = load i64, i64* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %24, i64 %25)
%27 = load i8*, i8** %7
%28 = load i64, i64* %6
%29 = call i32 @truncate64(i8* %27, i64 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %38
31: ; preds = %16
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %7
%34 = load i64, i64* %6
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %33, i64 %34, i32 %36)
store i32 1, i32* %3
br label %39
38: ; preds = %16
store i32 0, i32* %3
br label %39
39: ; preds = %38, %31, %10
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage: %s <path> <size>\0A\00"
@.str.2 = [23 x i8] c"Truncating %s to %lld\0A\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Could not truncate %s to %lld bytes: %s\0A\00"
@errno = global i32 0
@str = [34 x i8] c" size is expected to be in bytes\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %22
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @atoll(i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %10, i64 %13)
%15 = tail call i32 @truncate64(i8* %10, i64 %13)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %10, i64 %13, i32 %20)
br label %22
22: ; preds = %8, %17, %4
%23 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %8 ]
ret i32 %23
}