#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 */

/* Variables and functions */
int /*<<< orphan*/ bad_header(char *);
int /*<<< orphan*/ do_tag(char, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int read_header(char *magic) {
  char *p, *q, *p0;
  size_t n;
  int first, done;
  p0 = NULL;
  if (getline(&p0, &n, stdin) == -1) {
    free(p0);
    return 0;
  }
  q = p = p0;
  first = 1;
  done = 0;
  while (!done) {
    while (*q != ' ' && *q != '\n')
      if (*q++ == '\0')
        bad_header(magic);
    done = (*q == '\n');
    *q = '\0';
    if (first)
      if (strcmp(p, magic) == 0)
        first = 0;
      else
        bad_header(magic);
    else
      do_tag(*p, p + 1);
    p = ++q;
  }
  free(p0);
  return 1;
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
jne    1198 <read_header+0x48>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bd <read_header+0x16d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c8 <read_header+0x78>
jmp    12ad <read_header+0x15d>
jmp    11cd <read_header+0x7d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x39(%rbp)
je     11f2 <read_header+0xa2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1202 <read_header+0xb2>
jmp    122b <read_header+0xdb>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1226 <read_header+0xd6>
mov    -0x10(%rbp),%rdi
call   1060 <bad_header@plt>
jmp    11cd <read_header+0x7d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x34(%rbp)
je     1282 <read_header+0x132>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1274 <read_header+0x124>
movl   $0x0,-0x34(%rbp)
jmp    127d <read_header+0x12d>
mov    -0x10(%rbp),%rdi
call   1060 <bad_header@plt>
jmp    1298 <read_header+0x148>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
movsbl %al,%edi
call   1040 <do_tag@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
jmp    11b2 <read_header+0x62>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <getline@plt>
mov    (%rsp),%rbp
cmp    $0xffffffff,%eax
je     123f <read_header+0xef>
mov    $0x1,%r12d
jmp    1200 <read_header+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,-0x1(%rbp)
test   %r12d,%r12d
jne    11d0 <read_header+0x80>
movsbl (%r15),%edi
add    $0x1,%r15
mov    %r15,%rsi
call   1040 <do_tag@plt>
xor    %r12d,%r12d
cmp    $0xa,%bl
jne    1200 <read_header+0xb0>
jmp    1234 <read_header+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b9 <read_header+0x69>
mov    %r14,%rdi
call   1060 <bad_header@plt>
mov    $0x1,%r12d
cmp    $0xa,%bl
je     1234 <read_header+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%r15
add    $0x1,%rbp
jmp    1214 <read_header+0xc4>
nopl   0x0(%rax)
add    $0x1,%rbp
movzbl -0x1(%rbp),%ebx
cmp    $0xa,%bl
je     11a0 <read_header+0x50>
cmp    $0x20,%bl
je     11a0 <read_header+0x50>
test   %bl,%bl
jne    1210 <read_header+0xc0>
mov    %r14,%rdi
call   1060 <bad_header@plt>
jmp    1210 <read_header+0xc0>
mov    $0x1,%ebx
mov    (%rsp),%rbp
jmp    1241 <read_header+0xf1>
xor    %ebx,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @read_header(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %6
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %6, i64* %7, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %6
%15 = call i32 @free(i8* %14)
store i32 0, i32* %2
br label %76
16: ; preds = %1
%17 = load i8*, i8** %6
store i8* %17, i8** %4
store i8* %17, i8** %5
store i32 1, i32* %8
store i32 0, i32* %9
br label %18
18: ; preds = %70, %16
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %73
22: ; preds = %18
br label %23
23: ; preds = %44, %22
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 32
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br label %33
33: ; preds = %28, %23
%34 = phi i1 [ false, %23 ], [ %32, %28 ]
br i1 %34, label %35, label %45
35: ; preds = %33
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
%38 = load i8, i8* %36
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = call i32 @bad_header(i8* %42)
br label %44
44: ; preds = %41, %35
br label %23
45: ; preds = %33
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 10
%50 = zext i1 %49 to i32
store i32 %50, i32* %9
%51 = load i8*, i8** %5
store i8 0, i8* %51
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %45
%55 = load i8*, i8** %4
%56 = load i8*, i8** %3
%57 = call i64 @strcmp(i8* %55, i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 0, i32* %8
br label %63
60: ; preds = %54
%61 = load i8*, i8** %3
%62 = call i32 @bad_header(i8* %61)
br label %63
63: ; preds = %60, %59
br label %70
64: ; preds = %45
%65 = load i8*, i8** %4
%66 = load i8, i8* %65
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = call i32 @do_tag(i8 signext %66, i8* %68)
br label %70
70: ; preds = %64, %63
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %5
store i8* %72, i8** %4
br label %18
73: ; preds = %18
%74 = load i8*, i8** %6
%75 = call i32 @free(i8* %74)
store i32 1, i32* %2
br label %76
76: ; preds = %73, %13
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @read_header(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
store i8* null, i8** %2
%6 = load i32, i32* @stdin
%7 = call i32 @getline(i8** %2, i64* %3, i32 %6)
%8 = icmp eq i32 %7, -1
%9 = load i8*, i8** %2
br i1 %8, label %39, label %10
10: ; preds = %1, %34
%11 = phi i32 [ %35, %34 ], [ 1, %1 ]
%12 = phi i8* [ %36, %34 ], [ %9, %1 ]
br label %13
13: ; preds = %21, %10
%14 = phi i8* [ %12, %10 ], [ %17, %21 ]
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 32, label %22
i8 10, label %22
]
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = icmp eq i8 %15, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @bad_header(i8* %0)
br label %21
21: ; preds = %19, %16
br label %13
22: ; preds = %13, %13
%23 = icmp eq i8 %15, 10
store i8 0, i8* %14
%24 = icmp eq i32 %11, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i64 @strcmp(i8* %12, i8* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = call i32 @bad_header(i8* %0)
br label %34
30: ; preds = %22
%31 = load i8, i8* %12
%32 = getelementptr inbounds i8, i8* %12, i64 1
%33 = call i32 @do_tag(i8 signext %31, i8* %32)
br label %34
34: ; preds = %25, %28, %30
%35 = phi i32 [ 1, %28 ], [ 0, %30 ], [ 0, %25 ]
%36 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %23, label %37, label %10
37: ; preds = %34
%38 = load i8*, i8** %2
br label %39
39: ; preds = %1, %37
%40 = phi i8* [ %38, %37 ], [ %9, %1 ]
%41 = phi i32 [ 1, %37 ], [ 0, %1 ]
%42 = call i32 @free(i8* %40)
ret i32 %41
}