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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int truncate(char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s <db_file> <size>\n", argv[0]);
    printf("e.g., use '%s <db_file> 4096' to shrink db file to 4096 bytes.\n",
           argv[0]);
    printf("      use '%s <db_file> 0'    to recover db file to 64 Mbytes.\n",
           argv[0]);
    exit(-1);
  }
  char *file = argv[1];
  off_t length = atoi(argv[2]);
  if (length <= 0)
    length = 64 * 1024 * 1024;
  int ret = truncate(file, length);
  if (ret == 0)
    printf("truncate file: %s to %d bytes successfully.\n", file, (int)length);
  else
    printf("truncate file: %s failure.\n", file);
  return ret;
}


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     11a9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11d6 <main+0x96>
movl   $0x4000000,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <truncate@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1209 <main+0xc9>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121b <main+0xdb>
mov    -0x18(%rbp),%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    11a0 <main+0x60>
mov    0x8(%rbp),%r14
mov    0x10(%rbp),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
mov    $0x4000000,%ebx
cmovg  %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <truncate@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1186 <main+0x46>
lea    0xf4f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1199 <main+0x59>
lea    0xf0f(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp),%rsi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp),%rsi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: %s <db_file> <size>\0A\00"
@.str.1 = [64 x i8] c"e.g., use '%s <db_file> 4096' to shrink db file to 4096 bytes.\0A\00"
@.str.2 = [64 x i8] c" use '%s <db_file> 0' to recover db file to 64 Mbytes.\0A\00"
@.str.3 = [45 x i8] c"truncate file: %s to %d bytes successfully.\0A\00"
@.str.4 = [28 x i8] c"truncate file: %s failure.\0A\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 %25
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*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %25
store i32 67108864, i32* %7
br label %36
36: ; preds = %35, %25
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = call i32 @truncate(i8* %37, i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %44)
br label %49
46: ; preds = %36
%47 = load i8*, i8** %6
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %42
%50 = load i32, i32* %8
ret i32 %50
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: %s <db_file> <size>\0A\00"
@.str.1 = [64 x i8] c"e.g., use '%s <db_file> 4096' to shrink db file to 4096 bytes.\0A\00"
@.str.2 = [64 x i8] c" use '%s <db_file> 0' to recover db file to 64 Mbytes.\0A\00"
@.str.3 = [45 x i8] c"truncate file: %s to %d bytes successfully.\0A\00"
@.str.4 = [28 x i8] c"truncate file: %s failure.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp slt i32 %17, 1
%19 = select i1 %18, i32 67108864, i32 %17
%20 = tail call i32 @truncate(i8* %14, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %14, i32 %19)
br label %26
24: ; preds = %12
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %26
26: ; preds = %24, %22
ret i32 %20
}