#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 c;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeheader();
char getc(int /*<<< orphan*/ *);
char *gethline(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ parsefield(char *);
int /*<<< orphan*/ quit();
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
void scanheader(FILE *fd) {
  register char *p;
  register c;
  freeheader();
  for (;;) {
    p = gethline(fd);
    if (!p)
      break;
    c = getc(fd);
    while (c == ' ' || c == '\t') {
      register char *s, *p2, *np;
      int len;
      p2 = gethline(fd);
      if (!p2)
        break;
      for (s = p2; *s == ' ' || *s == '\t'; ++s)
        ;
      len = strlen(p) + strlen(s) + 1;
      if (len < 511) {
        np = malloc((unsigned)len + 1);
        if (!np) {
          error("out of memory");
          quit();
        }
        strcpy(np, p);
        strcat(np, " ");
        strcat(np, s);
        free(p);
        p = np;
      }
      free(p2);
      c = getc(fd);
    }
    ungetc(c, fd);
    parsefield(p);
    free(p);
  }
}


x86 assembly (clang, -O0):
<scanheader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1090 <freeheader@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <gethline@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <scanheader+0x30>
jmp    1372 <scanheader+0x1b2>
mov    -0x8(%rbp),%rdi
call   10e0 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x20,-0x14(%rbp)
mov    %al,-0x35(%rbp)
je     1218 <scanheader+0x58>
cmpl   $0x9,-0x14(%rbp)
sete   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1228 <scanheader+0x68>
jmp    134c <scanheader+0x18c>
mov    -0x8(%rbp),%rdi
call   10d0 <gethline@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1245 <scanheader+0x85>
jmp    134c <scanheader+0x18c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x36(%rbp)
je     1272 <scanheader+0xb2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
test   $0x1,%al
jne    1282 <scanheader+0xc2>
jmp    1298 <scanheader+0xd8>
jmp    1287 <scanheader+0xc7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    124d <scanheader+0x8d>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1ff,-0x34(%rbp)
jge    132f <scanheader+0x16f>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12f4 <scanheader+0x134>
lea    0xd18(%rip),%rdi
call   10b0 <error@plt>
mov    $0x0,%al
call   1060 <quit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xd02(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   10e0 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    11ff <scanheader+0x3f>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1080 <ungetc@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <parsefield@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    11d3 <scanheader+0x13>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanheader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
xor    %eax,%eax
call   1090 <freeheader@plt>
mov    %r12,%rdi
call   10d0 <gethline@plt>
test   %rax,%rax
je     12eb <scanheader+0x12b>
mov    %rax,%rbx
lea    0xe1e(%rip),%r15
jmp    122e <scanheader+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r12,%rsi
call   1080 <ungetc@plt>
mov    %rbx,%rdi
call   10a0 <parsefield@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   10d0 <gethline@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12eb <scanheader+0x12b>
mov    %r12,%rdi
call   10e0 <getc@plt>
movsbl %al,%ebp
cmp    $0x20,%ebp
je     1243 <scanheader+0x83>
cmp    $0x9,%ebp
jne    1200 <scanheader+0x40>
mov    %r12,%rdi
call   10d0 <gethline@plt>
test   %rax,%rax
je     1200 <scanheader+0x40>
mov    %rax,%r13
mov    %rax,%rbp
jmp    1264 <scanheader+0xa4>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
movzbl 0x0(%rbp),%eax
cmp    $0x20,%al
je     1260 <scanheader+0xa0>
cmp    $0x9,%al
je     1260 <scanheader+0xa0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    %r14d,%eax
cmp    $0x1fd,%eax
jg     12de <scanheader+0x11e>
add    $0x2,%eax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    12b2 <scanheader+0xf2>
lea    0xd5a(%rip),%rdi
call   10b0 <error@plt>
xor    %eax,%eax
call   1060 <quit@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rbx
mov    %r13,%rdi
call   1030 <free@plt>
jmp    122e <scanheader+0x6e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [2 x i8] c" \00"
@c = global i8 0
define void @scanheader(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %2
%9 = call i32 (...) @freeheader()
br label %10
10: ; preds = %88, %1
%11 = load i32*, i32** %2
%12 = call i8* @gethline(i32* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
br label %97
16: ; preds = %10
%17 = load i32*, i32** %2
%18 = call signext i8 @getc(i32* %17)
%19 = sext i8 %18 to i32
store i32 %19, i32* %4
br label %20
20: ; preds = %82, %16
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 32
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 9
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ true, %20 ], [ %25, %23 ]
br i1 %27, label %28, label %88
28: ; preds = %26
%29 = load i32*, i32** %2
%30 = call i8* @gethline(i32* %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %28
br label %88
34: ; preds = %28
%35 = load i8*, i8** %6
store i8* %35, i8** %5
br label %36
36: ; preds = %49, %34
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 32
br i1 %40, label %46, label %41
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 9
br label %46
46: ; preds = %41, %36
%47 = phi i1 [ true, %36 ], [ %45, %41 ]
br i1 %47, label %48, label %52
48: ; preds = %46
br label %49
49: ; preds = %48
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
br label %36
52: ; preds = %46
%53 = load i8*, i8** %3
%54 = call i32 @strlen(i8* %53)
%55 = load i8*, i8** %5
%56 = call i32 @strlen(i8* %55)
%57 = add nsw i32 %54, %56
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp slt i32 %59, 511
br i1 %60, label %61, label %82
61: ; preds = %52
%62 = load i32, i32* %8
%63 = add i32 %62, 1
%64 = call i8* @malloc(i32 %63)
store i8* %64, i8** %7
%65 = load i8*, i8** %7
%66 = icmp ne i8* %65, null
br i1 %66, label %70, label %67
67: ; preds = %61
%68 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%69 = call i32 (...) @quit()
br label %70
70: ; preds = %67, %61
%71 = load i8*, i8** %7
%72 = load i8*, i8** %3
%73 = call i32 @strcpy(i8* %71, i8* %72)
%74 = load i8*, i8** %7
%75 = call i32 @strcat(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%76 = load i8*, i8** %7
%77 = load i8*, i8** %5
%78 = call i32 @strcat(i8* %76, i8* %77)
%79 = load i8*, i8** %3
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %7
store i8* %81, i8** %3
br label %82
82: ; preds = %70, %52
%83 = load i8*, i8** %6
%84 = call i32 @free(i8* %83)
%85 = load i32*, i32** %2
%86 = call signext i8 @getc(i32* %85)
%87 = sext i8 %86 to i32
store i32 %87, i32* %4
br label %20
88: ; preds = %33, %26
%89 = load i32, i32* %4
%90 = trunc i32 %89 to i8
%91 = load i32*, i32** %2
%92 = call i32 @ungetc(i8 signext %90, i32* %91)
%93 = load i8*, i8** %3
%94 = call i32 @parsefield(i8* %93)
%95 = load i8*, i8** %3
%96 = call i32 @free(i8* %95)
br label %10
97: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [2 x i8] c" \00"
@c = global i8 0
define void @scanheader(i32* %0) {
%2 = tail call i32 (...) @freeheader()
%3 = tail call i8* @gethline(i32* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %45, label %5
5: ; preds = %1, %37
%6 = phi i8* [ %38, %37 ], [ %3, %1 ]
%7 = tail call signext i8 @getc(i32* %0)
%8 = sext i8 %7 to i32
switch i32 %8, label %39 [
i32 32, label %9
i32 9, label %9
]
9: ; preds = %5, %5
%10 = tail call i8* @gethline(i32* %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %39, label %12
12: ; preds = %9, %15
%13 = phi i8* [ %16, %15 ], [ %10, %9 ]
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 32, label %15
i8 9, label %15
]
15: ; preds = %12, %12
%16 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
17: ; preds = %12
%18 = tail call i32 @strlen(i8* %6)
%19 = tail call i32 @strlen(i8* %13)
%20 = add nsw i32 %19, %18
%21 = icmp slt i32 %20, 510
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = add nsw i32 %20, 2
%24 = tail call i8* @malloc(i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 (...) @quit()
br label %29
29: ; preds = %26, %22
%30 = tail call i32 @strcpy(i8* %24, i8* %6)
%31 = tail call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @strcat(i8* %24, i8* %13)
%33 = tail call i32 @free(i8* %6)
br label %34
34: ; preds = %17, %29
%35 = phi i8* [ %24, %29 ], [ %6, %17 ]
%36 = tail call i32 @free(i8* %10)
br label %37
37: ; preds = %34, %39
%38 = phi i8* [ %35, %34 ], [ %43, %39 ]
br label %5
39: ; preds = %9, %5
%40 = tail call i32 @ungetc(i8 signext %7, i32* %0)
%41 = tail call i32 @parsefield(i8* %6)
%42 = tail call i32 @free(i8* %6)
%43 = tail call i8* @gethline(i32* %0)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %37
45: ; preds = %39, %1
ret void
}