#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 */
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
scalar_t__ isspace(unsigned char);
size_t strcspn(char *, char *);
char *cli_read_line(FILE *fp, char *in, size_t len) {
  char *p, *t;
  if (fgets(in, len, fp) == NULL)
    return (NULL);
  p = in;
  in[strcspn(in, "\n")] = '\0';
  while (isspace(*(unsigned char *)p))
    p++;
  if (p[0] == '#' || p[0] == '\0') {
    p[0] = '\0';
    return (p);
  }
  for (t = p; *t != '\0'; t++) {
    if (*t == '\t')
      *t = ' ';
  }
  return (p);
}


x86 assembly (clang, -O0):
<cli_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    116c <cli_read_line+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    123f <cli_read_line+0x10f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11be <cli_read_line+0x8e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1197 <cli_read_line+0x67>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     11de <cli_read_line+0xae>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f2 <cli_read_line+0xc2>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <cli_read_line+0x10f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1237 <cli_read_line+0x107>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
jne    1221 <cli_read_line+0xf1>
mov    -0x30(%rbp),%rax
movb   $0x20,(%rax)
jmp    1226 <cli_read_line+0xf6>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11fa <cli_read_line+0xca>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_read_line>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a6 <cli_read_line+0x76>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
nopl   (%rax)
movzbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <cli_read_line+0x30>
lea    -0x1(%rbx),%rax
mov    -0x1(%rbx),%cl
test   %cl,%cl
je     1181 <cli_read_line+0x51>
cmp    $0x23,%cl
jne    119b <cli_read_line+0x6b>
movb   $0x0,(%rax)
jmp    11a4 <cli_read_line+0x74>
cs nopw 0x0(%rax,%rax,1)
movb   $0x20,-0x1(%rbx)
movzbl (%rbx),%ecx
add    $0x1,%rbx
cmp    $0x9,%cl
je     1190 <cli_read_line+0x60>
test   %cl,%cl
jne    1194 <cli_read_line+0x64>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i8* @cli_read_line(i32* nocapture %0, i8* %1, i64 %2) {
%4 = tail call i32* @fgets(i8* %1, i64 %2, i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = tail call i64 @strcspn(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 0, i8* %8
br label %9
9: ; preds = %9, %6
%10 = phi i8* [ %1, %6 ], [ %14, %9 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isspace(i8 zeroext %11)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = load i8, i8* %10
switch i8 %16, label %18 [
i8 35, label %17
i8 0, label %17
]
17: ; preds = %15, %15
store i8 0, i8* %10
br label %25
18: ; preds = %15, %22
%19 = phi i8 [ %24, %22 ], [ %16, %15 ]
%20 = phi i8* [ %23, %22 ], [ %10, %15 ]
switch i8 %19, label %22 [
i8 0, label %25
i8 9, label %21
]
21: ; preds = %18
store i8 32, i8* %20
br label %22
22: ; preds = %18, %21
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = load i8, i8* %23
br label %18
25: ; preds = %18, %3, %17
%26 = phi i8* [ %10, %17 ], [ null, %3 ], [ %10, %18 ]
ret i8* %26
}