#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 *, int, int /*<<< orphan*/ *);
char *strchr(char *, char);
int readline(FILE *str, char *dest, int destlen) {
  char *x;
  for (;;) {
    if (!fgets(dest, destlen, str))
      return -1;
    if (x = strchr(dest, '\n'))
      *x = '\0';
    if (dest[0] == '\0')
      continue;
    if (dest[0] == ';')
      continue;
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    1158 <readline+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <readline+0x91>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     117b <readline+0x5b>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1190 <readline+0x70>
jmp    1133 <readline+0x13>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    11a5 <readline+0x85>
jmp    1133 <readline+0x13>
jmp    11aa <readline+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    $0xffffffff,%r14d
jmp    115e <readline+0x3e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     1186 <readline+0x66>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <readline+0x57>
movb   $0x0,(%rax)
movzbl 0x0(%rbp),%eax
cmp    $0x3b,%al
je     1150 <readline+0x30>
test   %al,%al
je     1150 <readline+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readline(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %9
9: ; preds = %35, %28, %3
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = load i32*, i32** %5
%13 = call i32 @fgets(i8* %10, i32 %11, i32* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %9
store i32 -1, i32* %4
br label %38
16: ; preds = %9
%17 = load i8*, i8** %6
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i8*, i8** %8
store i8 0, i8* %21
br label %22
22: ; preds = %20, %16
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %9
29: ; preds = %22
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 59
br i1 %34, label %35, label %36
35: ; preds = %29
br label %9
36: ; preds = %29
br label %37
37: ; preds = %36
store i32 0, i32* %4
br label %38
38: ; preds = %37, %15
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @readline(i32* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @fgets(i8* %1, i32 %2, i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3, %12
%7 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 0, i8* %7
br label %10
10: ; preds = %9, %6
%11 = load i8, i8* %1
switch i8 %11, label %15 [
i8 0, label %12
i8 59, label %12
]
12: ; preds = %10, %10
%13 = tail call i32 @fgets(i8* %1, i32 %2, i32* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %12, %10, %3
%16 = phi i32 [ -1, %3 ], [ 0, %10 ], [ -1, %12 ]
ret i32 %16
}