#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;
typedef int mode_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ abort();
scalar_t__ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ftruncate(int, int /*<<< orphan*/);
int /*<<< orphan*/ get_size(char const *);
int getopt(int, char **, char *);
int open(char const *, int, ...);
size_t optind;
int optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *fname;
  const char *szstr;
  off_t sz;
  int create = 0;
  int option;
  int fd;
  while ((option = getopt(argc, argv, "c")) != -1) {
    switch (option) {
    case 'c':
      create = 1;
      break;
    case '?':
      fprintf(stderr,
              "trunc"
              ": Unrecognized option `%c'.\n\n",
              optopt);
      usage(stderr);
      exit(EXIT_FAILURE);
    default:
      abort();
    }
  }
  if (argv[optind] == NULL || argv[optind + 1] == NULL ||
      argv[optind + 2] != NULL) {
    usage(stderr);
    exit(EXIT_FAILURE);
  }
  fname = argv[optind];
  szstr = argv[optind + 1];
  sz = get_size(szstr);
  if (create) {
    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    fd = open(fname, O_WRONLY | O_CREAT, mode);
  } else {
    fd = open(fname, O_WRONLY);
  }
  if (fd == -1) {
    perror("trunc"
           ": open");
    exit(EXIT_FAILURE);
  }
  if (ftruncate(fd, sz) == -1) {
    perror("trunc"
           ": truncate");
    exit(EXIT_FAILURE);
  }
  if (close(fd) < 0) {
    perror("trunc"
           ": close");
    exit(EXIT_FAILURE);
  }
  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)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe35(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1253 <main+0xb3>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     120d <main+0x6d>
jmp    11f0 <main+0x50>
mov    -0x38(%rbp),%eax
sub    $0x63,%eax
jne    1247 <main+0xa7>
jmp    1201 <main+0x61>
movl   $0x1,-0x28(%rbp)
jmp    124e <main+0xae>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
lea    0xddc(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    11bd <main+0x1d>
mov    -0x10(%rbp),%rax
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12a0 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x2d51(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,0x8(%rax,%rcx,8)
je     12a0 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x2d37(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,0x10(%rax,%rcx,8)
je     12bc <main+0x11c>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d01(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ceb(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <get_size@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1360 <main+0x1c0>
mov    0x2c92(%rip),%rax
mov    (%rax),%eax
mov    0x2cc1(%rip),%rcx
or     (%rcx),%eax
mov    0x2c98(%rip),%rcx
or     (%rcx),%eax
mov    0x2cbf(%rip),%rcx
or     (%rcx),%eax
mov    0x2c7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2c4d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2c45(%rip),%rax
mov    (%rax),%esi
mov    0x2cac(%rip),%rax
or     (%rax),%esi
mov    -0x34(%rbp),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x30(%rbp)
jmp    1377 <main+0x1d7>
mov    -0x18(%rbp),%rdi
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    139b <main+0x1fb>
lea    0xc9d(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    13c9 <main+0x229>
lea    0xc7b(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    13f5 <main+0x255>
lea    0xc5f(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2bb2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1,%cl
lea    0xe4b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   10b0 <getopt@plt>
xor    %ecx,%ecx
cmp    $0x63,%eax
je     11c0 <main+0x20>
cmp    $0xffffffff,%eax
jne    12b1 <main+0x111>
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
mov    (%r15,%rax,8),%r14
test   %r14,%r14
je     12f0 <main+0x150>
mov    0x8(%r15,%rax,8),%rdi
test   %rdi,%rdi
je     12f0 <main+0x150>
cmpq   $0x0,0x10(%r15,%rax,8)
jne    12f0 <main+0x150>
call   1030 <get_size@plt>
mov    %eax,%ebp
test   $0x1,%bl
je     1231 <main+0x91>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <open@plt>
jmp    1283 <main+0xe3>
mov    0x2d60(%rip),%rax
mov    0x2d91(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d66(%rip),%rax
or     (%rax),%edx
mov    0x2d8d(%rip),%rax
or     (%rax),%edx
mov    0x2d4c(%rip),%rax
or     (%rax),%edx
mov    0x2d1b(%rip),%rax
or     (%rax),%edx
mov    0x2d1a(%rip),%rax
mov    0x2d83(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12fb <main+0x15b>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     1309 <main+0x169>
mov    %ebx,%edi
call   1060 <close@plt>
test   %rax,%rax
js     1317 <main+0x177>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x3f,%eax
jne    12e9 <main+0x149>
mov    0x2cfb(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
lea    0xd33(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
call   1080 <usage@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   1040 <abort@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
jmp    12d6 <main+0x136>
lea    0xd23(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x13b>
lea    0xd21(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x13b>
lea    0xd23(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x13b>

LLVM IR (-O0):
@.str = [2 x i8] c"c\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"trunc: Unrecognized option `%c'.\0A\0A\00"
@optopt = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [12 x i8] c"trunc: open\00"
@.str.3 = [16 x i8] c"trunc: truncate\00"
@.str.4 = [13 x i8] c"trunc: close\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
br label %13
13: ; preds = %31, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %10
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %32
18: ; preds = %13
%19 = load i32, i32* %10
switch i32 %19, label %29 [
i32 99, label %20
i32 63, label %21
]
20: ; preds = %18
store i32 1, i32* %9
br label %31
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @optopt
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stderr
%26 = call i32 @usage(i32 %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %20
br label %13
32: ; preds = %13
%33 = load i8**, i8*** %5
%34 = load i64, i64* @optind
%35 = getelementptr inbounds i8*, i8** %33, i64 %34
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %52, label %38
38: ; preds = %32
%39 = load i8**, i8*** %5
%40 = load i64, i64* @optind
%41 = add i64 %40, 1
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = icmp eq i8* %43, null
br i1 %44, label %52, label %45
45: ; preds = %38
%46 = load i8**, i8*** %5
%47 = load i64, i64* @optind
%48 = add i64 %47, 2
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %57
52: ; preds = %45, %38, %32
%53 = load i32, i32* @stderr
%54 = call i32 @usage(i32 %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %45
%58 = load i8**, i8*** %5
%59 = load i64, i64* @optind
%60 = getelementptr inbounds i8*, i8** %58, i64 %59
%61 = load i8*, i8** %60
store i8* %61, i8** %6
%62 = load i8**, i8*** %5
%63 = load i64, i64* @optind
%64 = add i64 %63, 1
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
store i8* %66, i8** %7
%67 = load i8*, i8** %7
%68 = call i32 @get_size(i8* %67)
store i32 %68, i32* %8
%69 = load i32, i32* %9
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %89
71: ; preds = %57
%72 = load i32, i32* @S_IRUSR
%73 = load i32, i32* @S_IWUSR
%74 = or i32 %72, %73
%75 = load i32, i32* @S_IRGRP
%76 = or i32 %74, %75
%77 = load i32, i32* @S_IWGRP
%78 = or i32 %76, %77
%79 = load i32, i32* @S_IROTH
%80 = or i32 %78, %79
%81 = load i32, i32* @S_IWOTH
%82 = or i32 %80, %81
store i32 %82, i32* %12
%83 = load i8*, i8** %6
%84 = load i32, i32* @O_WRONLY
%85 = load i32, i32* @O_CREAT
%86 = or i32 %84, %85
%87 = load i32, i32* %12
%88 = call i32 (i8*, i32, ...) @open(i8* %83, i32 %86, i32 %87)
store i32 %88, i32* %11
br label %93
89: ; preds = %57
%90 = load i8*, i8** %6
%91 = load i32, i32* @O_WRONLY
%92 = call i32 (i8*, i32, ...) @open(i8* %90, i32 %91)
store i32 %92, i32* %11
br label %93
93: ; preds = %89, %71
%94 = load i32, i32* %11
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %100
96: ; preds = %93
%97 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%98 = load i32, i32* @EXIT_FAILURE
%99 = call i32 @exit(i32 %98)
unreachable
100: ; preds = %93
%101 = load i32, i32* %11
%102 = load i32, i32* %8
%103 = call i32 @ftruncate(i32 %101, i32 %102)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %109
105: ; preds = %100
%106 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%107 = load i32, i32* @EXIT_FAILURE
%108 = call i32 @exit(i32 %107)
unreachable
109: ; preds = %100
%110 = load i32, i32* %11
%111 = call i64 @close(i32 %110)
%112 = icmp slt i64 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %109
%114 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%115 = load i32, i32* @EXIT_FAILURE
%116 = call i32 @exit(i32 %115)
unreachable
117: ; preds = %109
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"c\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"trunc: Unrecognized option `%c'.\0A\0A\00"
@optopt = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [12 x i8] c"trunc: open\00"
@.str.3 = [16 x i8] c"trunc: truncate\00"
@.str.4 = [13 x i8] c"trunc: close\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i1 [ true, %2 ], [ false, %3 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %14 [
i32 -1, label %16
i32 99, label %3
i32 63, label %6
]
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i32, i32* @optopt
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 @usage(i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %3
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %3
%17 = load i64, i64* @optind
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = add i64 %17, 1
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = add i64 %17, 2
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %36, label %31
31: ; preds = %26, %21, %16
%32 = load i32, i32* @stderr
%33 = tail call i32 @usage(i32 %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
%37 = tail call i32 @get_size(i8* %24)
br i1 %4, label %54, label %38
38: ; preds = %36
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %40, %39
%42 = load i32, i32* @S_IRGRP
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWGRP
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IROTH
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IWOTH
%49 = or i32 %47, %48
%50 = load i32, i32* @O_WRONLY
%51 = load i32, i32* @O_CREAT
%52 = or i32 %51, %50
%53 = tail call i32 (i8*, i32, ...) @open(i8* %19, i32 %52, i32 %49)
br label %57
54: ; preds = %36
%55 = load i32, i32* @O_WRONLY
%56 = tail call i32 (i8*, i32, ...) @open(i8* %19, i32 %55)
br label %57
57: ; preds = %54, %38
%58 = phi i32 [ %53, %38 ], [ %56, %54 ]
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = tail call i32 @exit(i32 %62)
unreachable
64: ; preds = %57
%65 = tail call i32 @ftruncate(i32 %58, i32 %37)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = tail call i32 @exit(i32 %69)
unreachable
71: ; preds = %64
%72 = tail call i64 @close(i32 %58)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = tail call i32 @exit(i32 %76)
unreachable
78: ; preds = %71
ret i32 0
}