#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 */
struct sa_open_data {
  int dummy;
};
typedef int /*<<< orphan*/ lbuf;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sa_open_data_dump(struct sa_open_data *);
int /*<<< orphan*/ salist_close(struct sa_open_data *);
int /*<<< orphan*/ salist_cmd_parse(struct sa_open_data *, char *,
                                    int /*<<< orphan*/);
struct sa_open_data *salist_open();
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int main(int argc, char *argv[]) {
  struct sa_open_data *od;
  char lbuf[128];
  od = salist_open();
  while (fgets(lbuf, sizeof(lbuf), stdin)) {
    size_t llen = strlen(lbuf);
    if (llen > 0 && lbuf[llen - 1] == '\n')
      lbuf[--llen] = '\0';
    if (llen > 0 && lbuf[llen - 1] == '\r')
      lbuf[--llen] = '\0';
    if (llen == 0)
      continue;
    salist_cmd_parse(od, lbuf, 0);
  }
  salist_close(od);
  sa_open_data_dump(od);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <salist_open@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1273 <main+0x113>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jbe    1202 <main+0xa2>
mov    -0xa8(%rbp),%rax
sub    $0x1,%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1202 <main+0xa2>
mov    -0xa8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0xa8(%rbp)
movb   $0x0,-0xa1(%rbp,%rax,1)
cmpq   $0x0,-0xa8(%rbp)
jbe    1249 <main+0xe9>
mov    -0xa8(%rbp),%rax
sub    $0x1,%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    1249 <main+0xe9>
mov    -0xa8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0xa8(%rbp)
movb   $0x0,-0xa1(%rbp,%rax,1)
cmpq   $0x0,-0xa8(%rbp)
jne    125c <main+0xfc>
jmp    1184 <main+0x24>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
xor    %edx,%edx
call   1030 <salist_cmd_parse@plt>
jmp    1184 <main+0x24>
mov    -0x18(%rbp),%rdi
call   1060 <salist_close@plt>
mov    -0x18(%rbp),%rdi
call   1070 <sa_open_data_dump@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1080 <salist_open@plt>
mov    %rax,%r14
mov    0x2e6b(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rsp,%rbx
jmp    11c2 <main+0x62>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <salist_cmd_parse@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11ad <main+0x4d>
lea    -0x1(%rax),%rcx
movzbl -0x1(%rsp,%rax,1),%edx
cmp    $0xa,%dl
jne    11f2 <main+0x92>
movb   $0x0,(%rsp,%rcx,1)
test   %rcx,%rcx
je     11ad <main+0x4d>
mov    %rax,%rcx
add    $0xfffffffffffffffe,%rcx
movzbl -0x2(%rsp,%rax,1),%edx
cmp    $0xd,%dl
jne    11a0 <main+0x40>
movb   $0x0,(%rsp,%rcx,1)
test   %rcx,%rcx
jne    11a0 <main+0x40>
jmp    11ad <main+0x4d>
mov    %r14,%rdi
call   1060 <salist_close@plt>
mov    %r14,%rdi
call   1070 <sa_open_data_dump@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sa_open_data = type { i32 }
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sa_open_data*
%7 = alloca [128 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.sa_open_data* (...) @salist_open()
store %struct.sa_open_data* %9, %struct.sa_open_data** %6
br label %10
10: ; preds = %49, %48, %2
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %11, i32 128, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %53
15: ; preds = %10
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = icmp ugt i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i64, i64* %8
%22 = sub i64 %21, 1
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i64, i64* %8
%29 = add i64 %28, -1
store i64 %29, i64* %8
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %27, %20, %15
%32 = load i64, i64* %8
%33 = icmp ugt i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i64, i64* %8
%36 = sub i64 %35, 1
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 13
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i64, i64* %8
%43 = add i64 %42, -1
store i64 %43, i64* %8
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %41, %34, %31
%46 = load i64, i64* %8
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
br label %10
49: ; preds = %45
%50 = load %struct.sa_open_data*, %struct.sa_open_data** %6
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%52 = call i32 @salist_cmd_parse(%struct.sa_open_data* %50, i8* %51, i32 0)
br label %10
53: ; preds = %10
%54 = load %struct.sa_open_data*, %struct.sa_open_data** %6
%55 = call i32 @salist_close(%struct.sa_open_data* %54)
%56 = load %struct.sa_open_data*, %struct.sa_open_data** %6
%57 = call i32 @sa_open_data_dump(%struct.sa_open_data* %56)
ret i32 0
}

LLVM IR (-O2):
%struct.sa_open_data = type { i32 }
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call %struct.sa_open_data* (...) @salist_open()
%6 = load i32, i32* @stdin
%7 = call i64 @fgets(i8* %4, i32 128, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %2, %32
%10 = call i64 @strlen(i8* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = add i64 %10, -1
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %23
17: ; preds = %12
store i8 0, i8* %14
%18 = icmp eq i64 %13, 0
br i1 %18, label %32, label %19
19: ; preds = %17
%20 = add i64 %10, -2
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
br label %23
23: ; preds = %19, %12
%24 = phi i8 [ %22, %19 ], [ %15, %12 ]
%25 = phi i64 [ %20, %19 ], [ %13, %12 ]
%26 = icmp eq i8 %24, 13
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %28
%29 = icmp eq i64 %25, 0
br i1 %29, label %32, label %30
30: ; preds = %23, %27
%31 = call i32 @salist_cmd_parse(%struct.sa_open_data* %5, i8* %4, i32 0)
br label %32
32: ; preds = %9, %17, %27, %30
%33 = load i32, i32* @stdin
%34 = call i64 @fgets(i8* %4, i32 128, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %9
36: ; preds = %32, %2
%37 = call i32 @salist_close(%struct.sa_open_data* %5)
%38 = call i32 @sa_open_data_dump(%struct.sa_open_data* %5)
ret i32 0
}