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

/* Variables and functions */
int /*<<< orphan*/ _test_sysio_shutdown();
int /*<<< orphan*/ doit(char const *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int getopt(int, char *const *, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *const argv[]) {
  int i;
  int err;
  int n;
  extern int _test_sysio_startup(void);
  while ((i = getopt(argc, argv, "")) != -1)
    switch (i) {
    default:
      usage();
    }
  err = _test_sysio_startup();
  if (err) {
    errno = -err;
    perror("sysio startup");
    exit(1);
  }
  n = argc - optind;
  while (optind < argc) {
    const char *path;
    path = argv[optind++];
    (void)doit(path);
  }
  if (!n) {
    int doflush;
    static char buf[4096];
    size_t len;
    char *cp;
    char c;
    doflush = 0;
    while (fgets(buf, sizeof(buf), stdin) != NULL) {
      len = strlen(buf);
      cp = buf + len - 1;
      c = *cp;
      *cp = '\0';
      if (!doflush)
        doit(buf);
      doflush = c == '\n' ? 0 : 1;
    }
  }
  _test_sysio_shutdown();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11d1 <main+0x41>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    11a6 <main+0x16>
call   1080 <_test_sysio_startup@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1207 <main+0x77>
xor    %ecx,%ecx
sub    -0x18(%rbp),%ecx
mov    0x2de1(%rip),%rax
mov    %ecx,(%rax)
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2dcf(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    125c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d9f(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <doit@plt>
jmp    1216 <main+0x86>
cmpl   $0x0,-0x1c(%rbp)
jne    12f8 <main+0x168>
movl   $0x0,-0x2c(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
lea    0x2e13(%rip),%rdi
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12f3 <main+0x163>
lea    0x2df8(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0x2de8(%rip),%rax
add    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x41(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x2c(%rbp)
jne    12da <main+0x14a>
lea    0x2dbb(%rip),%rdi
call   1060 <doit@plt>
movsbl -0x41(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xa,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
jmp    126d <main+0xdd>
jmp    12f8 <main+0x168>
mov    $0x0,%al
call   1030 <_test_sysio_shutdown@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe6a(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
je     11d9 <main+0x49>
lea    0xe59(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x30>
call   1080 <_test_sysio_startup@plt>
test   %eax,%eax
jne    12a4 <main+0x114>
mov    0x2df3(%rip),%rbp
mov    0x0(%rbp),%r15d
cmp    %ebx,%r15d
jge    1218 <main+0x88>
mov    %r15d,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%ecx
mov    %ecx,0x0(%rbp)
cltq
mov    (%r14,%rax,8),%rdi
call   1060 <doit@plt>
mov    0x0(%rbp),%eax
cmp    %ebx,%eax
jl     1200 <main+0x70>
cmp    %ebx,%r15d
jne    1290 <main+0x100>
mov    0x2dc4(%rip),%r14
mov    (%r14),%edx
lea    0x2e62(%rip),%r15
mov    %r15,%rdi
mov    $0x1000,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1290 <main+0x100>
xor    %ebp,%ebp
jmp    126e <main+0xde>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
cmp    $0xa,%bl
setne  %bpl
mov    (%r14),%edx
mov    %r15,%rdi
mov    $0x1000,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1290 <main+0x100>
mov    %r15,%rdi
call   1040 <strlen@plt>
movzbl -0x1(%rax,%r15,1),%ebx
movb   $0x0,-0x1(%rax,%r15,1)
test   %ebp,%ebp
jne    1250 <main+0xc0>
mov    %r15,%rdi
call   1060 <doit@plt>
jmp    1250 <main+0xc0>
xor    %eax,%eax
call   1030 <_test_sysio_shutdown@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
neg    %eax
mov    0x2d23(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd4a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@optind = global i32 0
@main.buf = internal global [4096 x i8] zeroinitializer
@stdin = 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
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %14
14: ; preds = %23, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* %6
switch i32 %20, label %21 [
]
21: ; preds = %19
%22 = call i32 (...) @usage()
br label %23
23: ; preds = %21
br label %14
24: ; preds = %14
%25 = call i32 @_test_sysio_startup()
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* %7
%30 = sub nsw i32 0, %29
store i32 %30, i32* @errno
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = load i32, i32* %4
%35 = load i32, i32* @optind
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %8
br label %37
37: ; preds = %41, %33
%38 = load i32, i32* @optind
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i8**, i8*** %5
%43 = load i32, i32* @optind
%44 = add nsw i32 %43, 1
store i32 %44, i32* @optind
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
%47 = load i8*, i8** %46
store i8* %47, i8** %9
%48 = load i8*, i8** %9
%49 = call i32 @doit(i8* %48)
br label %37
50: ; preds = %37
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 0
br i1 %52, label %77, label %53
53: ; preds = %50
store i32 0, i32* %10
br label %54
54: ; preds = %70, %53
%55 = load i32, i32* @stdin
%56 = call i32* @fgets(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0), i32 4096, i32 %55)
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %76
58: ; preds = %54
%59 = call i64 @strlen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0))
store i64 %59, i64* %11
%60 = load i64, i64* %11
%61 = getelementptr inbounds i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0), i64 %60
%62 = getelementptr inbounds i8, i8* %61, i64 -1
store i8* %62, i8** %12
%63 = load i8*, i8** %12
%64 = load i8, i8* %63
store i8 %64, i8* %13
%65 = load i8*, i8** %12
store i8 0, i8* %65
%66 = load i32, i32* %10
%67 = icmp ne i32 %66, 0
br i1 %67, label %70, label %68
68: ; preds = %58
%69 = call i32 @doit(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0))
br label %70
70: ; preds = %68, %58
%71 = load i8, i8* %13
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 10
%74 = zext i1 %73 to i64
%75 = select i1 %73, i32 0, i32 1
store i32 %75, i32* %10
br label %54
76: ; preds = %54
br label %77
77: ; preds = %76, %50
%78 = call i32 (...) @_test_sysio_shutdown()
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@optind = global i32 0
@main.buf = internal global [4096 x i8] zeroinitializer
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 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 (...) @usage()
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 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 = tail call i32 @_test_sysio_startup()
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = sub nsw i32 0, %10
store i32 %13, i32* @errno
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = load i32, i32* @optind
%18 = icmp slt i32 %17, %0
br i1 %18, label %19, label %28
19: ; preds = %16, %19
%20 = phi i32 [ %26, %19 ], [ %17, %16 ]
%21 = add nsw i32 %20, 1
store i32 %21, i32* @optind
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @doit(i8* %24)
%26 = load i32, i32* @optind
%27 = icmp slt i32 %26, %0
br i1 %27, label %19, label %28
28: ; preds = %19, %16
%29 = icmp eq i32 %17, %0
br i1 %29, label %30, label %49
30: ; preds = %28
%31 = load i32, i32* @stdin
%32 = tail call i32* @fgets(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0), i32 4096, i32 %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %49, label %34
34: ; preds = %30, %43
%35 = phi i32 [ %45, %43 ], [ 0, %30 ]
%36 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0))
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = load i8, i8* %38
store i8 0, i8* %38
%40 = icmp eq i32 %35, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = tail call i32 @doit(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0))
br label %43
43: ; preds = %41, %34
%44 = icmp ne i8 %39, 10
%45 = zext i1 %44 to i32
%46 = load i32, i32* @stdin
%47 = tail call i32* @fgets(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf, i64 0, i64 0), i32 4096, i32 %46)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %34
49: ; preds = %43, %30, %28
%50 = tail call i32 (...) @_test_sysio_shutdown()
ret i32 0
}