#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
char *basename(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int get_character(int);
int /*<<< orphan*/ init_raw(int);
int isatty(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  bool keep_running = false;
  bool print_prompt;
  int i;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--all")) {
      keep_running = true;
    } else if (!strcmp(argv[i], "--help")) {
      printf("Usage: %s [-a]\n"
             " -a, --all               Read all characters until EOF.\n",
             basename(argv[0]));
      return EXIT_SUCCESS;
    } else {
      fprintf(stderr,
              "Unknown option: %s\n"
              "Usage: %s [-a]\n",
              argv[i], basename(argv[0]));
      return EXIT_FAILURE;
    }
  }
  init_raw(true);
  print_prompt = isatty(STDIN_FILENO);
  do {
    keep_running &= get_character(print_prompt);
  } while (keep_running);
  init_raw(false);
  return EXIT_SUCCESS;
}


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,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    129d <main+0x12d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11e2 <main+0x72>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11ee <main+0x7e>
movl   $0x1,-0x14(%rbp)
jmp    128a <main+0x11a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe08(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <basename@plt>
mov    %rax,%rsi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e3 <main+0x173>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <basename@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xde4(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e3 <main+0x173>
jmp    128f <main+0x11f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <main+0x24>
mov    $0x1,%edi
call   1090 <init_raw@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <get_character@plt>
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12b8 <main+0x148>
xor    %edi,%edi
call   1090 <init_raw@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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
xor    %ebp,%ebp
cmp    $0x2,%edi
jl     1221 <main+0xb1>
mov    %rsi,%r14
mov    %edi,%r13d
mov    $0x1,%ebp
lea    0xe68(%rip),%r15
lea    0xe64(%rip),%r12
jmp    11b9 <main+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     121c <main+0xac>
mov    (%r14,%rbp,8),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b0 <main+0x40>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b0 <main+0x40>
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     126a <main+0xfa>
mov    0x2deb(%rip),%rax
mov    (%rax),%ebp
mov    (%r14),%rdi
call   1080 <basename@plt>
lea    0xe52(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2dbe(%rip),%rax
jmp    1259 <main+0xe9>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1090 <init_raw@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <get_character@plt>
and    %eax,%ebp
jne    1240 <main+0xd0>
xor    %edi,%edi
call   1090 <init_raw@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rdi
call   1080 <basename@plt>
lea    0xd97(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    1252 <main+0xe2>

LLVM IR (-O0):
@.str = [3 x i8] c"-a\00"
@.str.1 = [6 x i8] c"--all\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [72 x i8] c"Usage: %s [-a]\0A -a, --all Read all characters until EOF.\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.4 = [35 x i8] c"Unknown option: %s\0AUsage: %s [-a]\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %8
br label %9
9: ; preds = %59, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %62
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %21, %13
store i32 1, i32* %6
br label %58
30: ; preds = %21
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %30
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i8* @basename(i8* %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_SUCCESS
store i32 %44, i32* %3
br label %77
45: ; preds = %30
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i8* @basename(i8* %54)
%56 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %51, i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %77
58: ; preds = %29
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %9
62: ; preds = %9
%63 = call i32 @init_raw(i32 1)
%64 = load i32, i32* @STDIN_FILENO
%65 = call i32 @isatty(i32 %64)
store i32 %65, i32* %7
br label %66
66: ; preds = %71, %62
%67 = load i32, i32* %7
%68 = call i32 @get_character(i32 %67)
%69 = load i32, i32* %6
%70 = and i32 %69, %68
store i32 %70, i32* %6
br label %71
71: ; preds = %66
%72 = load i32, i32* %6
%73 = icmp ne i32 %72, 0
br i1 %73, label %66, label %74
74: ; preds = %71
%75 = call i32 @init_raw(i32 0)
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %3
br label %77
77: ; preds = %74, %45, %38
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"-a\00"
@.str.1 = [6 x i8] c"--all\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [72 x i8] c"Usage: %s [-a]\0A -a, --all Read all characters until EOF.\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.4 = [35 x i8] c"Unknown option: %s\0AUsage: %s [-a]\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %30
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %15
%7 = phi i64 [ 1, %4 ], [ %16, %15 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %6
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %30, label %6
18: ; preds = %12
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %1
%23 = tail call i8* @basename(i8* %22)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %42
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %1
%28 = tail call i8* @basename(i8* %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* %28)
br label %42
30: ; preds = %15, %2
%31 = phi i32 [ 0, %2 ], [ 1, %15 ]
%32 = tail call i32 @init_raw(i32 1)
%33 = load i32, i32* @STDIN_FILENO
%34 = tail call i32 @isatty(i32 %33)
br label %35
35: ; preds = %35, %30
%36 = phi i32 [ %31, %30 ], [ %38, %35 ]
%37 = tail call i32 @get_character(i32 %34)
%38 = and i32 %37, %36
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %35
40: ; preds = %35
%41 = tail call i32 @init_raw(i32 0)
br label %42
42: ; preds = %40, %25, %21
%43 = phi i32* [ @EXIT_FAILURE, %25 ], [ @EXIT_SUCCESS, %21 ], [ @EXIT_SUCCESS, %40 ]
%44 = load i32, i32* %43
ret i32 %44
}