#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*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int truncate(char const *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  const char *filename;
  off_t trunced_len;
  int r;
  if (argc != 3) {
    printf("Usage: %s <filename> <desired_length>\n", argv[0]);
    printf("Calls truncate(filename, desired_length).\n");
    exit(1);
  }
  filename = argv[1];
  trunced_len = atoi(argv[2]);
  r = truncate(filename, trunced_len);
  if (r < 0) {
    perror("truncate");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <truncate@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ea <main+0x9a>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <main+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x3,%edi
jne    119a <main+0x3a>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <truncate@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     1187 <main+0x27>
pop    %rbx
ret
lea    0xe99(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: %s <filename> <desired_length>\0A\00"
@.str.1 = [43 x i8] c"Calls truncate(filename, desired_length).\0A\00"
@.str.2 = [9 x i8] c"truncate\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @truncate(i8* %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %18
%32 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %34
33: ; preds = %18
store i32 0, i32* %3
br label %34
34: ; preds = %33, %31
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [39 x i8] c"Usage: %s <filename> <desired_length>\0A\00"
@.str.2 = [9 x i8] c"truncate\00"
@str = [42 x i8] c"Calls truncate(filename, desired_length).\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @truncate(i8* %11, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ 1, %17 ], [ 0, %9 ]
ret i32 %20
}