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

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
char *strstr(char *, char *);
char *read_line(char *l, size_t n, FILE *f) {
  char *t;
  if ((l = fgets(l, 80, f)) == NULL) {
    return NULL;
  }
  int len = strlen(l);
  while (len > 0 && (l[len - 1] == '\n' || l[len - 1] == '\r')) {
    l[len - 1] = 0;
    len--;
  }
  if ((t = strstr(l, "--")) != NULL) {
    *t = 0;
  }
  for (; *l == ' ' || *l == '\t'; l++)
    ;
  return l;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1171 <read_line+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1277 <read_line+0x147>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
jle    11cb <read_line+0x9b>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x2e(%rbp)
je     11c5 <read_line+0x95>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11db <read_line+0xab>
jmp    11fa <read_line+0xca>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    117d <read_line+0x4d>
mov    -0x10(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     121f <read_line+0xef>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    1224 <read_line+0xf4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x2f(%rbp)
je     1249 <read_line+0x119>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x2f(%rbp)
mov    -0x2f(%rbp),%al
test   $0x1,%al
jne    1259 <read_line+0x129>
jmp    126f <read_line+0x13f>
jmp    125e <read_line+0x12e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1224 <read_line+0xf4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbx
mov    $0x50,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11b1 <read_line+0x81>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    117f <read_line+0x4f>
mov    %eax,%eax
add    $0x1,%rax
jmp    116e <read_line+0x3e>
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jbe    117f <read_line+0x4f>
lea    -0x2(%rax),%ecx
movzbl (%rbx,%rcx,1),%edx
cmp    $0xd,%dl
je     1160 <read_line+0x30>
cmp    $0xa,%dl
je     1160 <read_line+0x30>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11a4 <read_line+0x74>
movb   $0x0,(%rax)
jmp    11a4 <read_line+0x74>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     11a0 <read_line+0x70>
cmp    $0x9,%al
je     11a0 <read_line+0x70>
jmp    11b3 <read_line+0x83>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"--\00"
define i8* @read_line(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = load i32*, i32** %7
%12 = call i8* @fgets(i8* %10, i32 80, i32* %11)
store i8* %12, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i8* null, i8** %4
br label %76
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %9
br label %18
18: ; preds = %43, %15
%19 = load i32, i32* %9
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = load i32, i32* %9
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %39, label %30
30: ; preds = %21
%31 = load i8*, i8** %5
%32 = load i32, i32* %9
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 13
br label %39
39: ; preds = %30, %21
%40 = phi i1 [ true, %21 ], [ %38, %30 ]
br label %41
41: ; preds = %39, %18
%42 = phi i1 [ false, %18 ], [ %40, %39 ]
br i1 %42, label %43, label %51
43: ; preds = %41
%44 = load i8*, i8** %5
%45 = load i32, i32* %9
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* %9
%50 = add nsw i32 %49, -1
store i32 %50, i32* %9
br label %18
51: ; preds = %41
%52 = load i8*, i8** %5
%53 = call i8* @strstr(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %53, i8** %8
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i8*, i8** %8
store i8 0, i8* %56
br label %57
57: ; preds = %55, %51
br label %58
58: ; preds = %71, %57
%59 = load i8*, i8** %5
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 32
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = load i8*, i8** %5
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 9
br label %68
68: ; preds = %63, %58
%69 = phi i1 [ true, %58 ], [ %67, %63 ]
br i1 %69, label %70, label %74
70: ; preds = %68
br label %71
71: ; preds = %70
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %5
br label %58
74: ; preds = %68
%75 = load i8*, i8** %5
store i8* %75, i8** %4
br label %76
76: ; preds = %74, %14
%77 = load i8*, i8** %4
ret i8* %77
}

LLVM IR (-O2):
@.str = [3 x i8] c"--\00"
define i8* @read_line(i8* %0, i64 %1, i32* nocapture %2) {
%4 = tail call i8* @fgets(i8* %0, i32 80, i32* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %17
%12 = phi i64 [ %10, %9 ], [ %13, %17 ]
%13 = add nsw i64 %12, -1
%14 = and i64 %13, 4294967295
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = load i8, i8* %15
switch i8 %16, label %19 [
i8 10, label %17
i8 13, label %17
]
17: ; preds = %11, %11
store i8 0, i8* %15
%18 = icmp ugt i64 %12, 1
br i1 %18, label %11, label %19
19: ; preds = %17, %11, %6
%20 = tail call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %19
store i8 0, i8* %20
br label %23
23: ; preds = %22, %19
br label %24
24: ; preds = %23, %27
%25 = phi i8* [ %28, %27 ], [ %4, %23 ]
%26 = load i8, i8* %25
switch i8 %26, label %29 [
i8 32, label %27
i8 9, label %27
]
27: ; preds = %24, %24
%28 = getelementptr inbounds i8, i8* %25, i64 1
br label %24
29: ; preds = %24, %3
%30 = phi i8* [ null, %3 ], [ %25, %24 ]
ret i8* %30
}