#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*/ LOG_ERR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeheader();
int getc(int /*<<< orphan*/ *);
char *gethline(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ parsefield(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
void scanheader(FILE *fd) {
  char *p;
  int c;
  freeheader();
  for (;;) {
    p = gethline(fd);
    if (!p)
      break;
    c = getc(fd);
    while (c == ' ' || c == '\t') {
      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) {
          syslog(LOG_ERR, "out of memory, aborted");
          exit(-1);
        }
        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   10c0 <gethline@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <scanheader+0x30>
jmp    1375 <scanheader+0x1b5>
mov    -0x8(%rbp),%rdi
call   10e0 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x20,-0x14(%rbp)
mov    %al,-0x35(%rbp)
je     1215 <scanheader+0x55>
cmpl   $0x9,-0x14(%rbp)
sete   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1225 <scanheader+0x65>
jmp    1352 <scanheader+0x192>
mov    -0x8(%rbp),%rdi
call   10c0 <gethline@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1242 <scanheader+0x82>
jmp    1352 <scanheader+0x192>
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     126f <scanheader+0xaf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
test   $0x1,%al
jne    127f <scanheader+0xbf>
jmp    1295 <scanheader+0xd5>
jmp    1284 <scanheader+0xc4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    124a <scanheader+0x8a>
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    1338 <scanheader+0x178>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12fd <scanheader+0x13d>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xd02(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <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>
mov    %eax,-0x14(%rbp)
jmp    11fc <scanheader+0x3c>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1070 <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,%r15
xor    %eax,%eax
call   1090 <freeheader@plt>
mov    %r15,%rdi
call   10c0 <gethline@plt>
test   %rax,%rax
je     12d5 <scanheader+0x115>
mov    %rax,%r13
lea    0xe27(%rip),%r14
jmp    122e <scanheader+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <ungetc@plt>
mov    %r13,%rdi
call   10a0 <parsefield@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   10c0 <gethline@plt>
mov    %rax,%r13
test   %rax,%rax
je     12d5 <scanheader+0x115>
mov    %r15,%rdi
call   10e0 <getc@plt>
mov    %eax,%ebx
cmp    $0x20,%eax
je     1242 <scanheader+0x82>
cmp    $0x9,%ebx
jne    1200 <scanheader+0x40>
mov    %r15,%rdi
call   10c0 <gethline@plt>
test   %rax,%rax
je     1200 <scanheader+0x40>
mov    %rax,%r12
mov    %rax,%rbx
jmp    1264 <scanheader+0xa4>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1260 <scanheader+0xa0>
cmp    $0x9,%al
je     1260 <scanheader+0xa0>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
cmp    $0x1fd,%eax
jg     12c8 <scanheader+0x108>
add    $0x2,%eax
mov    %eax,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     12e4 <scanheader+0x124>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbp,%r13
mov    %r12,%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
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd0c(%rip),%rsi
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [23 x i8] c"out of memory, aborted\00"
@.str.1 = [2 x i8] c" \00"
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 = %87, %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 %95
16: ; preds = %10
%17 = load i32*, i32** %2
%18 = call i32 @getc(i32* %17)
store i32 %18, i32* %4
br label %19
19: ; preds = %82, %16
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 32
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 9
br label %25
25: ; preds = %22, %19
%26 = phi i1 [ true, %19 ], [ %24, %22 ]
br i1 %26, label %27, label %87
27: ; preds = %25
%28 = load i32*, i32** %2
%29 = call i8* @gethline(i32* %28)
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %27
br label %87
33: ; preds = %27
%34 = load i8*, i8** %6
store i8* %34, i8** %5
br label %35
35: ; preds = %48, %33
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 32
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 9
br label %45
45: ; preds = %40, %35
%46 = phi i1 [ true, %35 ], [ %44, %40 ]
br i1 %46, label %47, label %51
47: ; preds = %45
br label %48
48: ; preds = %47
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %5
br label %35
51: ; preds = %45
%52 = load i8*, i8** %3
%53 = call i32 @strlen(i8* %52)
%54 = load i8*, i8** %5
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %53, %55
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 511
br i1 %59, label %60, label %82
60: ; preds = %51
%61 = load i32, i32* %8
%62 = add i32 %61, 1
%63 = call i8* @malloc(i32 %62)
store i8* %63, i8** %7
%64 = load i8*, i8** %7
%65 = icmp ne i8* %64, null
br i1 %65, label %70, label %66
66: ; preds = %60
%67 = load i32, i32* @LOG_ERR
%68 = call i32 @syslog(i32 %67, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %60
%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, %51
%83 = load i8*, i8** %6
%84 = call i32 @free(i8* %83)
%85 = load i32*, i32** %2
%86 = call i32 @getc(i32* %85)
store i32 %86, i32* %4
br label %19
87: ; preds = %32, %25
%88 = load i32, i32* %4
%89 = load i32*, i32** %2
%90 = call i32 @ungetc(i32 %88, i32* %89)
%91 = load i8*, i8** %3
%92 = call i32 @parsefield(i8* %91)
%93 = load i8*, i8** %3
%94 = call i32 @free(i8* %93)
br label %10
95: ; preds = %15
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [23 x i8] c"out of memory, aborted\00"
@.str.1 = [2 x i8] c" \00"
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 i32 @getc(i32* %0)
switch i32 %7, label %39 [
i32 32, label %8
i32 9, label %8
]
8: ; preds = %5, %5
%9 = tail call i8* @gethline(i32* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %39, label %11
11: ; preds = %8, %14
%12 = phi i8* [ %15, %14 ], [ %9, %8 ]
%13 = load i8, i8* %12
switch i8 %13, label %16 [
i8 32, label %14
i8 9, label %14
]
14: ; preds = %11, %11
%15 = getelementptr inbounds i8, i8* %12, i64 1
br label %11
16: ; preds = %11
%17 = tail call i32 @strlen(i8* %6)
%18 = tail call i32 @strlen(i8* %12)
%19 = add nsw i32 %18, %17
%20 = icmp slt i32 %19, 510
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = add nsw i32 %19, 2
%23 = tail call i8* @malloc(i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @LOG_ERR
%27 = tail call i32 @syslog(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %21
%30 = tail call i32 @strcpy(i8* %23, i8* %6)
%31 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @strcat(i8* %23, i8* %12)
%33 = tail call i32 @free(i8* %6)
br label %34
34: ; preds = %16, %29
%35 = phi i8* [ %23, %29 ], [ %6, %16 ]
%36 = tail call i32 @free(i8* %9)
br label %37
37: ; preds = %34, %39
%38 = phi i8* [ %35, %34 ], [ %43, %39 ]
br label %5
39: ; preds = %8, %5
%40 = tail call i32 @ungetc(i32 %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
}