#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*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
char *readline(char *string, FILE *infile, char *infilename) {
  char *result;
  do {
    result = fgets(string, 1024, infile);
    if (result == (char *)NULL) {
      printf("  Error:  Unexpected end of file in %s.\n", infilename);
      exit(1);
    }
    while ((*result != '\0') && (*result != '#') && (*result != '.') &&
           (*result != '+') && (*result != '-') &&
           ((*result < '0') || (*result > '9'))) {
      result++;
    }
  } while ((*result == '#') || (*result == '\0'));
  return result;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <readline+0x4f>
mov    -0x18(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1184 <readline+0x54>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1218 <readline+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x23,%ecx
mov    %al,-0x21(%rbp)
je     1218 <readline+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x21(%rbp)
je     1218 <readline+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2b,%ecx
mov    %al,-0x21(%rbp)
je     1218 <readline+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2d,%ecx
mov    %al,-0x21(%rbp)
je     1218 <readline+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x22(%rbp)
jl     1212 <readline+0xe2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1228 <readline+0xf8>
jmp    1239 <readline+0x109>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1184 <readline+0x54>
jmp    123e <readline+0x10e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x23,%ecx
mov    %al,-0x23(%rbp)
je     1263 <readline+0x133>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x23(%rbp)
mov    -0x23(%rbp),%al
test   $0x1,%al
jne    1144 <readline+0x14>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x400,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b2 <readline+0x82>
movabs $0x800000001,%r12
movabs $0x680000000000,%r13
jmp    1185 <readline+0x55>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b2 <readline+0x82>
movzbl (%rax),%ecx
cmp    $0x2e,%rcx
ja     119a <readline+0x6a>
bt     %rcx,%r12
jb     1170 <readline+0x40>
bt     %rcx,%r13
jb     11a8 <readline+0x78>
add    $0xc6,%cl
cmp    $0xf5,%cl
ja     11a8 <readline+0x78>
add    $0x1,%rax
jmp    1185 <readline+0x55>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe47(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [41 x i8] c" Error: Unexpected end of file in %s.\0A\00"
define i8* @readline(i8* %0, i32* nocapture %1, i8* %2) {
%4 = tail call i8* @fgets(i8* %0, i32 1024, i32* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %19, %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3, %17
%10 = phi i8* [ %18, %17 ], [ %4, %3 ]
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 35, label %19
i8 0, label %19
i8 43, label %22
i8 45, label %22
i8 46, label %22
]
12: ; preds = %9
%13 = add i8 %11, -58
%14 = icmp ult i8 %13, -10
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %10, i64 1
br label %17
17: ; preds = %15, %19
%18 = phi i8* [ %16, %15 ], [ %20, %19 ]
br label %9
19: ; preds = %9, %9
%20 = tail call i8* @fgets(i8* %0, i32 1024, i32* %1)
%21 = icmp eq i8* %20, null
br i1 %21, label %6, label %17
22: ; preds = %9, %9, %9, %12
ret i8* %10
}