#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char *, struct stat *);
int truncate(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *src;
  off_t len;
  struct stat srcStat;
  if (argc != 3) {
    printf("%s [file] [length] \n", argv[0]);
    exit(1);
  }
  src = argv[1];
  len = atoi(argv[2]);
  if (0 != stat(src, &srcStat)) {
    printf("%s : Error with stat\n", src);
    perror("");
    exit(-1);
  }
  if (-1 == truncate(src, len)) {
    printf("%s : Error with ftruncate\n", src);
    perror("");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     1196 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11f3 <main+0x93>
mov    -0x18(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <truncate@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1234 <main+0xd4>
mov    -0x18(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
lea    0xdef(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    119f <main+0x3f>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
jne    11b8 <main+0x58>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <truncate@plt>
cmp    $0xffffffff,%eax
je     11c1 <main+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe56(%rip),%rdi
jmp    11c8 <main+0x68>
lea    0xe63(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [21 x i8] c"%s [file] [length] \0A\00"
@.str.1 = [22 x i8] c"%s : Error with stat\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [27 x i8] c"%s : Error with ftruncate\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %5
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i8*, i8** %5
%25 = call i64 @stat(i8* %24, %struct.stat* %7)
%26 = icmp ne i64 0, %25
br i1 %26, label %27, label %32
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %16
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = call i32 @truncate(i8* %33, i32 %34)
%36 = icmp eq i32 -1, %35
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [21 x i8] c"%s [file] [length] \0A\00"
@.str.1 = [22 x i8] c"%s : Error with stat\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [27 x i8] c"%s : Error with ftruncate\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = call i64 @stat(i8* %12, %struct.stat* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%20 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %10
%23 = call i32 @truncate(i8* %12, i32 %15)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%27 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
ret i32 0
}