#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printline(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char *buf = NULL;
  size_t siz = 0;
  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
    argc -= 1;
  if (argc > 1) {
    fprintf(stderr, "usage: %s\n", argv[0]);
    return 1;
  }
  printline("--- Program started ---\n");
  while (getline(&buf, &siz, stdin) != -1)
    printline(buf);
  printline("--- Program exited ---\n");
  free(buf);
  return 0;
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11b4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
jne    11b4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmpb   $0x0,0x2(%rax)
jne    11b4 <main+0x74>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11e6 <main+0xa6>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123b <main+0xfb>
lea    0xe1e(%rip),%rdi
call   1050 <printline@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     121f <main+0xdf>
mov    -0x18(%rbp),%rdi
call   1050 <printline@plt>
jmp    11f2 <main+0xb2>
lea    0xdfe(%rip),%rdi
call   1050 <printline@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jl     117c <main+0x3c>
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    11e5 <main+0xa5>
cmpb   $0x2d,0x1(%rax)
jne    11e5 <main+0xa5>
add    $0xfffffffd,%edi
cmp    $0xfffffffe,%edi
jb     11e5 <main+0xa5>
cmpb   $0x0,0x2(%rax)
jne    11e5 <main+0xa5>
lea    0xe88(%rip),%rdi
call   1050 <printline@plt>
mov    0x2e59(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x8c>
mov    %rsp,%r14
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
mov    (%rsp),%rdi
call   1050 <printline@plt>
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x70>
lea    0xe51(%rip),%rdi
call   1050 <printline@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1202 <main+0xc2>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe08(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"usage: %s\0A\00"
@.str.1 = [25 x i8] c"--- Program started ---\0A\00"
@stdin = global i32 0
@.str.2 = [24 x i8] c"--- Program exited ---\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %36
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %36
18: ; preds = %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br i1 %25, label %26, label %36
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %4
br label %36
36: ; preds = %33, %26, %18, %10, %2
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %58
45: ; preds = %36
%46 = call i32 @printline(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %51, %45
%48 = load i32, i32* @stdin
%49 = call i32 @getline(i8** %6, i64* %7, i32 %48)
%50 = icmp ne i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i8*, i8** %6
%53 = call i32 @printline(i8* %52)
br label %47
54: ; preds = %47
%55 = call i32 @printline(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8*, i8** %6
%57 = call i32 @free(i8* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %54, %39
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"usage: %s\0A\00"
@.str.1 = [25 x i8] c"--- Program started ---\0A\00"
@stdin = global i32 0
@.str.2 = [24 x i8] c"--- Program exited ---\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 45
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %10, i64 2
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
%21 = add nsw i32 %0, -3
%22 = icmp ult i32 %21, -2
%23 = or i1 %22, %20
br i1 %23, label %24, label %28
24: ; preds = %17, %8, %13
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %43
28: ; preds = %17, %2
%29 = tail call i32 @printline(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = call i32 @getline(i8** %3, i64* %4, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %39, label %33
33: ; preds = %28, %33
%34 = load i8*, i8** %3
%35 = call i32 @printline(i8* %34)
%36 = load i32, i32* @stdin
%37 = call i32 @getline(i8** %3, i64* %4, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %33
39: ; preds = %33, %28
%40 = call i32 @printline(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%41 = load i8*, i8** %3
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %39, %24
%44 = phi i32 [ 1, %24 ], [ 0, %39 ]
ret i32 %44
}