#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 */

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int ftruncate(int, int);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
int optind;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int truncate(char *, int);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int c, size = 0, result;
  int use_ftruncate = 0, fd;
  opterr = 0;
  while ((c = getopt(argc, argv, "fhs:")) != -1) {
    switch (c) {
    case 'f':
      use_ftruncate = 1;
      break;
    case 's':
      size = atoi(optarg);
      break;
    case 'h':
    default:
      usage();
      break;
    }
  }
  if (optind < argc) {
    if (use_ftruncate) {
      printf("Ftruncating %s to size %d\n", argv[optind], size);
      fd = open(argv[optind], O_WRONLY, 0);
      if (fd < 0) {
        printf("Error opening: %s\n", strerror(errno));
      } else {
        result = ftruncate(fd, size);
        if (result < 0) {
          printf("Error truncating: %d %s\n", errno, strerror(errno));
        }
        close(fd);
      }
    } else {
      printf("Truncating %s to size %d\n", argv[optind], size);
      result = truncate(argv[optind], size);
      if (result < 0) {
        printf("Error truncating: %d %s\n", errno, strerror(errno));
      }
    }
  } else {
    usage();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e0d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     124a <main+0xba>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x66,%eax
je     1217 <main+0x87>
jmp    11f5 <main+0x65>
mov    -0x28(%rbp),%eax
sub    $0x68,%eax
je     1239 <main+0xa9>
jmp    1206 <main+0x76>
mov    -0x28(%rbp),%eax
sub    $0x73,%eax
je     1223 <main+0x93>
jmp    123e <main+0xae>
movl   $0x1,-0x20(%rbp)
jmp    1245 <main+0xb5>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1245 <main+0xb5>
jmp    123e <main+0xae>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    11c2 <main+0x32>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    13b1 <main+0x221>
cmpl   $0x0,-0x20(%rbp)
je     132f <main+0x19f>
mov    -0x10(%rbp),%rax
mov    0x2d6f(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2d4c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12dc <main+0x14c>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    132a <main+0x19a>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <ftruncate@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1322 <main+0x192>
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%esi
mov    %rax,%rdx
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
jmp    13ac <main+0x21c>
mov    -0x10(%rbp),%rax
mov    0x2ca6(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2c83(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
call   1060 <truncate@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13a7 <main+0x217>
mov    0x2c50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x30(%rbp),%esi
mov    %rax,%rdx
lea    0xc93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13ac <main+0x21c>
jmp    13b8 <main+0x228>
mov    $0x0,%al
call   1070 <usage@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e21(%rip),%rax
movq   $0x0,(%rax)
mov    $0x1,%r12b
lea    0xe48(%rip),%r15
mov    0x2e39(%rip),%r13
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     1208 <main+0x78>
cmp    $0x66,%eax
je     11f5 <main+0x65>
cmp    $0x73,%eax
je     11fa <main+0x6a>
xor    %eax,%eax
call   1070 <usage@plt>
jmp    11d0 <main+0x40>
xor    %r12d,%r12d
jmp    11d0 <main+0x40>
mov    0x0(%r13),%edi
call   10a0 <atoi@plt>
mov    %eax,%r14d
jmp    11d0 <main+0x40>
mov    0x2dd1(%rip),%r15
movslq (%r15),%rax
cmp    %ebp,%eax
jge    1270 <main+0xe0>
mov    (%rbx,%rax,8),%rsi
test   $0x1,%r12b
je     127c <main+0xec>
lea    0xe25(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rdi
mov    %r14d,%esi
call   1060 <truncate@plt>
test   %eax,%eax
jns    1303 <main+0x173>
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xdd4(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1303 <main+0x173>
xor    %eax,%eax
call   1070 <usage@plt>
jmp    1303 <main+0x173>
lea    0xd82(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rdi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
test   %eax,%eax
js     12e4 <main+0x154>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14d,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
jns    12db <main+0x14b>
mov    0x2d11(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd64(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1303 <main+0x173>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd27(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@opterr = global i64 0
@.str = [5 x i8] c"fhs:\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [27 x i8] c"Ftruncating %s to size %d\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [19 x i8] c"Error opening: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"Error truncating: %d %s\0A\00"
@.str.4 = [26 x i8] c"Truncating %s to size %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
store i64 0, i64* @opterr
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %23 [
i32 102, label %18
i32 115, label %19
i32 104, label %22
]
18: ; preds = %16
store i32 1, i32* %9
br label %25
19: ; preds = %16
%20 = load i32, i32* @optarg
%21 = call i32 @atoi(i32 %20)
store i32 %21, i32* %7
br label %25
22: ; preds = %16
br label %23
23: ; preds = %16, %22
%24 = call i32 (...) @usage()
br label %25
25: ; preds = %23, %19, %18
br label %11
26: ; preds = %11
%27 = load i32, i32* @optind
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %93
30: ; preds = %26
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %69
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = load i32, i32* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39)
%41 = load i8**, i8*** %5
%42 = load i32, i32* @optind
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* @O_WRONLY
%47 = call i32 @open(i8* %45, i32 %46, i32 0)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %33
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %52)
br label %68
54: ; preds = %33
%55 = load i32, i32* %10
%56 = load i32, i32* %7
%57 = call i32 @ftruncate(i32 %55, i32 %56)
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %54
%61 = load i32, i32* @errno
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %61, i8* %63)
br label %65
65: ; preds = %60, %54
%66 = load i32, i32* %10
%67 = call i32 @close(i32 %66)
br label %68
68: ; preds = %65, %50
br label %92
69: ; preds = %30
%70 = load i8**, i8*** %5
%71 = load i32, i32* @optind
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %70, i64 %72
%74 = load i8*, i8** %73
%75 = load i32, i32* %7
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %74, i32 %75)
%77 = load i8**, i8*** %5
%78 = load i32, i32* @optind
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = load i32, i32* %7
%83 = call i32 @truncate(i8* %81, i32 %82)
store i32 %83, i32* %8
%84 = load i32, i32* %8
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %69
%87 = load i32, i32* @errno
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %87, i8* %89)
br label %91
91: ; preds = %86, %69
br label %92
92: ; preds = %91, %68
br label %95
93: ; preds = %26
%94 = call i32 (...) @usage()
br label %95
95: ; preds = %93, %92
ret i32 0
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [5 x i8] c"fhs:\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [27 x i8] c"Ftruncating %s to size %d\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [19 x i8] c"Error opening: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"Error truncating: %d %s\0A\00"
@.str.4 = [26 x i8] c"Truncating %s to size %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %8, %2
%4 = phi i1 [ true, %2 ], [ false, %8 ]
%5 = phi i32 [ 0, %2 ], [ %7, %8 ]
br label %6
6: ; preds = %3, %10
%7 = phi i32 [ %5, %3 ], [ %12, %10 ]
br label %8
8: ; preds = %6, %13
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %13 [
i32 -1, label %15
i32 102, label %3
i32 115, label %10
]
10: ; preds = %8
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %6
13: ; preds = %8
%14 = tail call i32 (...) @usage()
br label %8
15: ; preds = %8
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
br i1 %17, label %18, label %56
18: ; preds = %15
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
br i1 %4, label %44, label %22
22: ; preds = %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %7)
%24 = load i32, i32* @optind
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_WRONLY
%29 = tail call i32 @open(i8* %27, i32 %28, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %58
35: ; preds = %22
%36 = tail call i32 @ftruncate(i32 %29, i32 %7)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %39, i8* %40)
br label %42
42: ; preds = %38, %35
%43 = tail call i32 @close(i32 %29)
br label %58
44: ; preds = %18
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %21, i32 %7)
%46 = load i32, i32* @optind
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = tail call i32 @truncate(i8* %49, i32 %7)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %44
%53 = load i32, i32* @errno
%54 = tail call i8* @strerror(i32 %53)
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %54)
br label %58
56: ; preds = %15
%57 = tail call i32 (...) @usage()
br label %58
58: ; preds = %42, %31, %52, %44, %56
ret i32 0
}