#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ EX_IOERR;
int /*<<< orphan*/ O_RDWR;
int close(int);
int /*<<< orphan*/ emit_help();
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ optind;
int /*<<< orphan*/ trim_file(int, char *);
int main(int argc, char *argv[]) {
  int ch, fd;
  while ((ch = getopt(argc, argv, "h?")) != -1) {
    switch (ch) {
    case 'h':
    case '?':
    default:
      emit_help();
    }
  }
  argc -= optind;
  argv += optind;
  if (argc < 1)
    emit_help();
  while (*argv) {
    if ((fd = open(*argv, O_RDWR)) == -1)
      err(EX_IOERR, "could not open '%s'", *argv);
    trim_file(fd, *argv);
    if (close(fd) == -1)
      err(EX_IOERR, "could not close '%s'", *argv);
    argv++;
  }
  exit(EXIT_SUCCESS);
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11db <main+0x6b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x3f,%eax
je     11ca <main+0x5a>
jmp    11b9 <main+0x49>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
jne    11cf <main+0x5f>
jmp    11ca <main+0x5a>
jmp    11cf <main+0x5f>
mov    $0x0,%al
call   1030 <emit_help@plt>
jmp    1186 <main+0x16>
mov    0x2df6(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1216 <main+0xa6>
mov    $0x0,%al
call   1030 <emit_help@plt>
jmp    121b <main+0xab>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12b3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1266 <main+0xf6>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda2(%rip),%rsi
call   1050 <err@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1060 <trim_file@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    12a2 <main+0x132>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd7a(%rip),%rsi
call   1050 <err@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    121b <main+0xab>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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
lea    0xe79(%rip),%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11b9 <main+0x49>
lea    0xe68(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <emit_help@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x30>
mov    0x2e18(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
lea    (%rbx,%rax,8),%rbx
test   %ebp,%ebp
jg     11d4 <main+0x64>
xor    %eax,%eax
call   1030 <emit_help@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    11ea <main+0x7a>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2df7(%rip),%r12
mov    0x2de8(%rip),%r13
lea    0xe04(%rip),%r14
lea    0xe11(%rip),%r15
jmp    121d <main+0xad>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11dc <main+0x6c>
mov    (%r12),%esi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    123c <main+0xcc>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
mov    %r14,%rsi
call   1050 <err@plt>
mov    (%rbx),%rsi
mov    %ebp,%edi
call   1060 <trim_file@plt>
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0xa0>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
mov    %r15,%rsi
call   1050 <err@plt>
jmp    1210 <main+0xa0>

LLVM IR (-O0):
@.str = [3 x i8] c"h?\00"
@optind = global i64 0
@O_RDWR = global i32 0
@EX_IOERR = global i32 0
@.str.1 = [20 x i8] c"could not open '%s'\00"
@.str.2 = [21 x i8] c"could not close '%s'\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %18, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %16 [
i32 104, label %15
i32 63, label %15
]
15: ; preds = %13, %13
br label %16
16: ; preds = %13, %15
%17 = call i32 (...) @emit_help()
br label %18
18: ; preds = %16
br label %8
19: ; preds = %8
%20 = load i64, i64* @optind
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = sub nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %4
%25 = load i64, i64* @optind
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 %25
store i8** %27, i8*** %5
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = call i32 (...) @emit_help()
br label %32
32: ; preds = %30, %19
br label %33
33: ; preds = %61, %32
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %64
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDWR
%41 = call i32 @open(i8* %39, i32 %40)
store i32 %41, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i32, i32* @EX_IOERR
%45 = load i8**, i8*** %5
%46 = load i8*, i8** %45
%47 = call i32 @err(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %43, %37
%49 = load i32, i32* %7
%50 = load i8**, i8*** %5
%51 = load i8*, i8** %50
%52 = call i32 @trim_file(i32 %49, i8* %51)
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %61
56: ; preds = %48
%57 = load i32, i32* @EX_IOERR
%58 = load i8**, i8*** %5
%59 = load i8*, i8** %58
%60 = call i32 @err(i32 %57, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %56, %48
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i32 1
store i8** %63, i8*** %5
br label %33
64: ; preds = %33
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"h?\00"
@optind = global i64 0
@O_RDWR = global i32 0
@EX_IOERR = global i32 0
@.str.1 = [20 x i8] c"could not open '%s'\00"
@.str.2 = [21 x i8] c"could not close '%s'\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @emit_help()
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %5
9: ; preds = %5, %2
%10 = load i64, i64* @optind
%11 = trunc i64 %10 to i32
%12 = sub i32 %0, %11
%13 = getelementptr inbounds i8*, i8** %1, i64 %10
%14 = icmp slt i32 %12, 1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 (...) @emit_help()
br label %17
17: ; preds = %15, %9
%18 = load i8*, i8** %13
%19 = icmp eq i8* %18, null
br i1 %19, label %43, label %20
20: ; preds = %17, %39
%21 = phi i8* [ %41, %39 ], [ %18, %17 ]
%22 = phi i8** [ %40, %39 ], [ %13, %17 ]
%23 = load i32, i32* @O_RDWR
%24 = tail call i32 @open(i8* %21, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @EX_IOERR
%28 = load i8*, i8** %22
%29 = tail call i32 @err(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %20
%31 = load i8*, i8** %22
%32 = tail call i32 @trim_file(i32 %24, i8* %31)
%33 = tail call i32 @close(i32 %24)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* @EX_IOERR
%37 = load i8*, i8** %22
%38 = tail call i32 @err(i32 %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %35, %30
%40 = getelementptr inbounds i8*, i8** %22, i64 1
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %20
43: ; preds = %39, %17
%44 = load i32, i32* @EXIT_SUCCESS
%45 = tail call i32 @exit(i32 %44)
unreachable
}