#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char c;
int /*<<< orphan*/ error(char *);
char getc(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ quit();
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *gethline(FILE *fd) {
  register char *p;
  char line[512];
  register c;
  c = getc(fd);
  if (c < 0) {
    error("cannot read mail header");
    return (0);
  }
  for (p = line; c >= 0 && c != '\n'; c = getc(fd)) {
    *p++ = c;
    if (p - line >= sizeof(line) - 2) {
      error("too long header line");
      return (0);
    }
  }
  *p = 0;
  if (!line[0])
    return (0);
  p = malloc((unsigned)(strlen(line) + 1));
  if (!p) {
    error("out of memory");
    quit();
  }
  strcpy(p, line);
  return (p);
}


x86 assembly (clang, -O0):
<gethline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    11a7 <gethline+0x47>
lea    0xe6b(%rip),%rdi
call   1070 <error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c4 <gethline+0x164>
lea    -0x220(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x224(%rbp)
mov    %al,-0x225(%rbp)
jl     11d7 <gethline+0x77>
cmpl   $0xa,-0x224(%rbp)
setne  %al
mov    %al,-0x225(%rbp)
mov    -0x225(%rbp),%al
test   $0x1,%al
jne    11ea <gethline+0x8a>
jmp    1252 <gethline+0xf2>
mov    -0x224(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
lea    -0x220(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1fe,%rax
jb     1236 <gethline+0xd6>
lea    0xdf4(%rip),%rdi
call   1070 <error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c4 <gethline+0x164>
jmp    123b <gethline+0xdb>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x224(%rbp)
jmp    11b2 <gethline+0x52>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpb   $0x0,-0x220(%rbp)
jne    1273 <gethline+0x113>
movq   $0x0,-0x8(%rbp)
jmp    12c4 <gethline+0x164>
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12ac <gethline+0x14c>
lea    0xd8d(%rip),%rdi
call   1070 <error@plt>
mov    $0x0,%al
call   1050 <quit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethline>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
call   1080 <getc@plt>
test   %al,%al
js     117f <gethline+0x1f>
cmp    $0xa,%al
jne    1188 <gethline+0x28>
mov    %rsp,%rax
jmp    11b4 <gethline+0x54>
lea    0xe7a(%rip),%rdi
jmp    11fc <gethline+0x9c>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
cmp    $0x1fd,%rbx
je     11f5 <gethline+0x95>
mov    %r14,%rdi
call   1080 <getc@plt>
add    $0x1,%rbx
test   %al,%al
js     11b0 <gethline+0x50>
cmp    $0xa,%al
jne    1190 <gethline+0x30>
lea    (%rsp,%rbx,1),%rax
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
je     1201 <gethline+0xa1>
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e8 <gethline+0x88>
lea    0xe51(%rip),%rdi
call   1070 <error@plt>
xor    %eax,%eax
call   1050 <quit@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    1203 <gethline+0xa3>
lea    0xe1c(%rip),%rdi
call   1070 <error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"cannot read mail header\00"
@.str.1 = [21 x i8] c"too long header line\00"
@.str.2 = [14 x i8] c"out of memory\00"
@c = global i8 0
define i8* @gethline(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call signext i8 @getc(i32* %7)
%9 = sext i8 %8 to i32
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %64
14: ; preds = %1
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
store i8* %15, i8** %4
br label %16
16: ; preds = %38, %14
%17 = load i32, i32* %6
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 10
br label %22
22: ; preds = %19, %16
%23 = phi i1 [ false, %16 ], [ %21, %19 ]
br i1 %23, label %24, label %42
24: ; preds = %22
%25 = load i32, i32* %6
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
store i8 %26, i8* %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = icmp uge i64 %33, 510
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %64
37: ; preds = %24
br label %38
38: ; preds = %37
%39 = load i32*, i32** %3
%40 = call signext i8 @getc(i32* %39)
%41 = sext i8 %40 to i32
store i32 %41, i32* %6
br label %16
42: ; preds = %22
%43 = load i8*, i8** %4
store i8 0, i8* %43
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%45 = load i8, i8* %44
%46 = icmp ne i8 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %42
store i8* null, i8** %2
br label %64
48: ; preds = %42
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%50 = call i64 @strlen(i8* %49)
%51 = add nsw i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = call i8* @malloc(i32 %52)
store i8* %53, i8** %4
%54 = load i8*, i8** %4
%55 = icmp ne i8* %54, null
br i1 %55, label %59, label %56
56: ; preds = %48
%57 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 (...) @quit()
br label %59
59: ; preds = %56, %48
%60 = load i8*, i8** %4
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%62 = call i32 @strcpy(i8* %60, i8* %61)
%63 = load i8*, i8** %4
store i8* %63, i8** %2
br label %64
64: ; preds = %59, %47, %35, %12
%65 = load i8*, i8** %2
ret i8* %65
}

LLVM IR (-O2):
@.str = [24 x i8] c"cannot read mail header\00"
@.str.1 = [21 x i8] c"too long header line\00"
@.str.2 = [14 x i8] c"out of memory\00"
@c = global i8 0
define i8* @gethline(i32* nocapture %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call signext i8 @getc(i32* %0)
%5 = icmp slt i8 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = icmp eq i8 %4, 10
br i1 %7, label %24, label %8
8: ; preds = %6
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 509
br label %12
10: ; preds = %1
%11 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %39
12: ; preds = %8, %19
%13 = phi i8 [ %4, %8 ], [ %20, %19 ]
%14 = phi i8* [ %3, %8 ], [ %15, %19 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %13, i8* %14
%16 = icmp eq i8* %14, %9
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %39
19: ; preds = %12
%20 = call signext i8 @getc(i32* %0)
%21 = icmp sgt i8 %20, -1
%22 = icmp ne i8 %20, 10
%23 = and i1 %21, %22
br i1 %23, label %12, label %24
24: ; preds = %19, %6
%25 = phi i8* [ %3, %6 ], [ %15, %19 ]
store i8 0, i8* %25
%26 = load i8, i8* %3
%27 = icmp eq i8 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %24
%29 = call i64 @strlen(i8* %3)
%30 = trunc i64 %29 to i32
%31 = add i32 %30, 1
%32 = call i8* @malloc(i32 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (...) @quit()
br label %37
37: ; preds = %34, %28
%38 = call i32 @strcpy(i8* %32, i8* %3)
br label %39
39: ; preds = %24, %37, %17, %10
%40 = phi i8* [ null, %10 ], [ null, %17 ], [ %32, %37 ], [ null, %24 ]
ret i8* %40
}