#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*/ add_history(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ history_set_length(int);
int /*<<< orphan*/ printf(char *, ...);
char *readline(char *);
int /*<<< orphan*/ readline_print_keycodes();
int /*<<< orphan*/ readline_set_multiline(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ write_history(char *);
int main(int argc, char **argv) {
  char *line;
  char *prgname = argv[0];
  while (argc > 1) {
    argc--;
    argv++;
    if (!strcmp(*argv, "--multiline")) {
      readline_set_multiline(1);
      printf("Multi-line mode enabled.\n");
    } else if (!strcmp(*argv, "--keycodes")) {
      readline_print_keycodes();
      exit(0);
    } else {
      fprintf(stderr, "Usage: %s [--multiline] [--keycodes]\n", prgname);
      exit(1);
    }
  }
  add_history("history.txt");
  while ((line = readline("hello> ")) != NULL) {
    if (line[0] != '\0' && line[0] != '/') {
      printf("echo: '%s'\n", line);
      add_history(line);
      write_history("history.txt");
    } else if (!strncmp(line, "/historylen", 11)) {
      int len = atoi(line + 11);
      history_set_length(len);
    } else if (line[0] == '/') {
      printf("Unrecognized command: %s\n", line);
    }
    free(line);
  }
  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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    129b <main+0xcb>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xde2(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1249 <main+0x79>
mov    $0x1,%edi
call   1070 <readline_set_multiline@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1296 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcf(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1273 <main+0xa3>
mov    $0x0,%al
call   10d0 <readline_print_keycodes@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdaa(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    11f1 <main+0x21>
lea    0xdb5(%rip),%rdi
call   1050 <add_history@plt>
lea    0xdb5(%rip),%rdi
call   1090 <readline@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1382 <main+0x1b2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     130d <main+0x13d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     130d <main+0x13d>
mov    -0x18(%rbp),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <add_history@plt>
lea    0xd54(%rip),%rdi
call   1060 <write_history@plt>
jmp    1374 <main+0x1a4>
mov    -0x18(%rbp),%rdi
lea    0xd5f(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1348 <main+0x178>
mov    -0x18(%rbp),%rdi
add    $0xb,%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   10a0 <history_set_length@plt>
jmp    136f <main+0x19f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    136a <main+0x19a>
mov    -0x18(%rbp),%rsi
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    136f <main+0x19f>
jmp    1374 <main+0x1a4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    12a7 <main+0xd7>
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
cmp    $0x2,%edi
jl     1245 <main+0x65>
mov    %rsi,%r13
mov    %edi,%ebx
mov    (%rsi),%r14
add    $0x1,%ebx
add    $0x8,%r13
lea    0xdfa(%rip),%r15
lea    0xe76(%rip),%r12
nopl   (%rax)
mov    0x0(%r13),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   10c0 <strcmp@plt>
test   %eax,%eax
jne    1323 <main+0x143>
mov    $0x1,%edi
call   1080 <readline_set_multiline@plt>
mov    %r12,%rdi
call   1050 <puts@plt>
add    $0xffffffff,%ebx
add    $0x8,%r13
cmp    $0x2,%ebx
jg     1210 <main+0x30>
lea    0xdf1(%rip),%rdi
call   1060 <add_history@plt>
lea    0xdf1(%rip),%rdi
call   10a0 <readline@plt>
test   %rax,%rax
je     1312 <main+0x132>
mov    %rax,%rbx
lea    0xded(%rip),%r14
lea    0xdf2(%rip),%r15
lea    0xdcb(%rip),%r12
lea    0xdcc(%rip),%r13
lea    0xdb1(%rip),%rbp
jmp    12c5 <main+0xe5>
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1060 <add_history@plt>
mov    %rbp,%rdi
call   1070 <write_history@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   10a0 <readline@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1312 <main+0x132>
movzbl (%rbx),%eax
test   %al,%al
je     12d0 <main+0xf0>
cmp    $0x2f,%al
jne    1290 <main+0xb0>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1300 <main+0x120>
cmpb   $0x2f,(%rbx)
jne    12ad <main+0xcd>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    12ad <main+0xcd>
nopl   0x0(%rax,%rax,1)
lea    0xb(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   10b0 <history_set_length@plt>
jmp    12ad <main+0xcd>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce2(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <strcmp@plt>
test   %eax,%eax
jne    1344 <main+0x164>
xor    %eax,%eax
call   10e0 <readline_print_keycodes@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
mov    %r14,%rdx
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"--multiline\00"
@.str.1 = [26 x i8] c"Multi-line mode enabled.\0A\00"
@.str.2 = [11 x i8] c"--keycodes\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"Usage: %s [--multiline] [--keycodes]\0A\00"
@.str.4 = [12 x i8] c"history.txt\00"
@.str.5 = [8 x i8] c"hello> \00"
@.str.6 = [12 x i8] c"echo: '%s'\0A\00"
@.str.7 = [12 x i8] c"/historylen\00"
@.str.8 = [26 x i8] c"Unrecognized command: %s\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
store i8* %11, i8** %7
br label %12
12: ; preds = %40, %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %15
%25 = call i32 @readline_set_multiline(i32 1)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %40
27: ; preds = %15
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = call i32 (...) @readline_print_keycodes()
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %7
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %24
br label %12
41: ; preds = %12
%42 = call i32 @add_history(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %85, %41
%44 = call i8* @readline(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i8* %44, i8** %6
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %88
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %64
52: ; preds = %46
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 47
br i1 %57, label %58, label %64
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = load i8*, i8** %6
%62 = call i32 @add_history(i8* %61)
%63 = call i32 @write_history(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %85
64: ; preds = %52, %46
%65 = load i8*, i8** %6
%66 = call i32 @strncmp(i8* %65, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 11)
%67 = icmp ne i32 %66, 0
br i1 %67, label %74, label %68
68: ; preds = %64
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i64 11
%71 = call i32 @atoi(i8* %70)
store i32 %71, i32* %8
%72 = load i32, i32* %8
%73 = call i32 @history_set_length(i32 %72)
br label %84
74: ; preds = %64
%75 = load i8*, i8** %6
%76 = getelementptr inbounds i8, i8* %75, i64 0
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 47
br i1 %79, label %80, label %83
80: ; preds = %74
%81 = load i8*, i8** %6
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %74
br label %84
84: ; preds = %83, %68
br label %85
85: ; preds = %84, %58
%86 = load i8*, i8** %6
%87 = call i32 @free(i8* %86)
br label %43
88: ; preds = %43
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"--multiline\00"
@.str.2 = [11 x i8] c"--keycodes\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"Usage: %s [--multiline] [--keycodes]\0A\00"
@.str.4 = [12 x i8] c"history.txt\00"
@.str.5 = [8 x i8] c"hello> \00"
@.str.6 = [12 x i8] c"echo: '%s'\0A\00"
@.str.7 = [12 x i8] c"/historylen\00"
@.str.8 = [26 x i8] c"Unrecognized command: %s\0A\00"
@str = [25 x i8] c"Multi-line mode enabled.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %27
5: ; preds = %2, %12
%6 = phi i32 [ %13, %12 ], [ %0, %2 ]
%7 = phi i8** [ %8, %12 ], [ %1, %2 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %5
%13 = add nsw i32 %6, -1
%14 = tail call i32 @readline_set_multiline(i32 1)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%16 = icmp sgt i32 %6, 2
br i1 %16, label %5, label %27
17: ; preds = %5
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 (...) @readline_print_keycodes()
%22 = tail call i32 @exit(i32 0)
unreachable
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %12, %2
%28 = tail call i32 @add_history(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i8* @readline(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %54, label %31
31: ; preds = %27, %50
%32 = phi i8* [ %52, %50 ], [ %29, %27 ]
%33 = load i8, i8* %32
switch i8 %33, label %34 [
i8 0, label %38
i8 47, label %38
]
34: ; preds = %31
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%36 = tail call i32 @add_history(i8* %32)
%37 = tail call i32 @write_history(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %50
38: ; preds = %31, %31
%39 = tail call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 11)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = getelementptr inbounds i8, i8* %32, i64 11
%43 = tail call i32 @atoi(i8* %42)
%44 = tail call i32 @history_set_length(i32 %43)
br label %50
45: ; preds = %38
%46 = load i8, i8* %32
%47 = icmp eq i8 %46, 47
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %32)
br label %50
50: ; preds = %41, %48, %45, %34
%51 = tail call i32 @free(i8* %32)
%52 = tail call i8* @readline(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %31
54: ; preds = %50, %27
ret i32 0
}