#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 EOF;
int /*<<< orphan*/ error_msg_and_die(char *, char *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
scalar_t__ isalnum(char);
char tolower(char);
char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc) {
  char *s, *hdrval;
  int c;
  *istrunc = 0;
  if (fgets(buf, bufsiz, fp) == NULL)
    return NULL;
  for (s = buf; *s == '\r'; ++s)
    ;
  if (s[0] == '\n')
    return NULL;
  for (s = buf; isalnum(*s) || *s == '-'; ++s)
    *s = tolower(*s);
  if (*s != ':')
    error_msg_and_die("bad header line: %s", buf);
  for (*s++ = '\0'; *s == ' ' || *s == '\t'; ++s)
    ;
  hdrval = s;
  while (*s != '\0' && *s != '\r' && *s != '\n')
    ++s;
  if (*s != '\0') {
    *s = '\0';
    return hdrval;
  }
  while (c = getc(fp), c != EOF && c != '\n')
    ;
  *istrunc = 1;
  return hdrval;
}


x86 assembly (clang, -O0):
<gethdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    119a <gethdr+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    13ad <gethdr+0x25d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11c8 <gethdr+0x78>
jmp    11b7 <gethdr+0x67>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11a2 <gethdr+0x52>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11e5 <gethdr+0x95>
movq   $0x0,-0x8(%rbp)
jmp    13ad <gethdr+0x25d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x3d(%rbp)
jne    121b <gethdr+0xcb>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    122b <gethdr+0xdb>
jmp    1250 <gethdr+0x100>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1060 <tolower@plt>
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ed <gethdr+0x9d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1270 <gethdr+0x120>
mov    -0x10(%rbp),%rsi
lea    0xd95(%rip),%rdi
call   1050 <error_msg_and_die@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x3e(%rbp)
je     12a7 <gethdr+0x157>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
test   $0x1,%al
jne    12b7 <gethdr+0x167>
jmp    12cd <gethdr+0x17d>
jmp    12bc <gethdr+0x16c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1282 <gethdr+0x132>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x3f(%rbp)
je     130f <gethdr+0x1bf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x3f(%rbp)
je     130f <gethdr+0x1bf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x3f(%rbp)
mov    -0x3f(%rbp),%al
test   $0x1,%al
jne    131f <gethdr+0x1cf>
jmp    1330 <gethdr+0x1e0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12d5 <gethdr+0x185>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1354 <gethdr+0x204>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13ad <gethdr+0x25d>
jmp    1359 <gethdr+0x209>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%ecx
xor    %eax,%eax
mov    0x2c77(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x40(%rbp)
je     1386 <gethdr+0x236>
cmpl   $0xa,-0x3c(%rbp)
setne  %al
mov    %al,-0x40(%rbp)
mov    -0x40(%rbp),%al
test   $0x1,%al
jne    1396 <gethdr+0x246>
jmp    139b <gethdr+0x24b>
jmp    1359 <gethdr+0x209>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethdr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
movl   $0x0,(%rcx)
call   1040 <fgets@plt>
test   %rax,%rax
je     1193 <gethdr+0x43>
mov    %r12,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rax),%ecx
cmp    $0xd,%cl
jne    118e <gethdr+0x3e>
add    $0x1,%rax
jmp    1180 <gethdr+0x30>
cmp    $0xa,%cl
jne    119a <gethdr+0x4a>
xor    %ebx,%ebx
jmp    124a <gethdr+0xfa>
lea    0x1(%r12),%rbx
jmp    11bf <gethdr+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbx)
add    $0x1,%rbx
movsbl -0x1(%rbx),%edi
call   1030 <isalnum@plt>
movzbl -0x1(%rbx),%ecx
test   %rax,%rax
jne    11b0 <gethdr+0x60>
cmp    $0x2d,%cl
je     11b0 <gethdr+0x60>
cmp    $0x3a,%cl
je     11ea <gethdr+0x9a>
lea    0xe1e(%rip),%rdi
mov    %r12,%rsi
call   1050 <error_msg_and_die@plt>
movb   $0x0,-0x1(%rbx)
jmp    11f4 <gethdr+0xa4>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x9,%al
je     11f0 <gethdr+0xa0>
cmp    $0x20,%al
je     11f0 <gethdr+0xa0>
lea    0x1(%rbx),%rcx
cmp    $0xd,%al
je     1223 <gethdr+0xd3>
nopw   0x0(%rax,%rax,1)
cmp    $0xa,%al
je     1223 <gethdr+0xd3>
test   %al,%al
je     1229 <gethdr+0xd9>
movzbl (%rcx),%eax
add    $0x1,%rcx
cmp    $0xd,%al
jne    1210 <gethdr+0xc0>
movb   $0x0,-0x1(%rcx)
jmp    124a <gethdr+0xfa>
mov    0x2db8(%rip),%r12
mov    %r15,%rdi
call   1070 <getc@plt>
cmp    $0xa,%eax
je     1243 <gethdr+0xf3>
cmp    (%r12),%eax
jne    1230 <gethdr+0xe0>
movl   $0x1,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"bad header line: %s\00"
@EOF = global i32 0
define i8* @gethdr(i8* %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%13 = load i32*, i32** %9
store i32 0, i32* %13
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = load i32*, i32** %8
%17 = call i32* @fgets(i8* %14, i64 %15, i32* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %4
store i8* null, i8** %5
br label %133
20: ; preds = %4
%21 = load i8*, i8** %6
store i8* %21, i8** %10
br label %22
22: ; preds = %28, %20
%23 = load i8*, i8** %10
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 13
br i1 %26, label %27, label %31
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %10
br label %22
31: ; preds = %22
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %31
store i8* null, i8** %5
br label %133
38: ; preds = %31
%39 = load i8*, i8** %6
store i8* %39, i8** %10
br label %40
40: ; preds = %57, %38
%41 = load i8*, i8** %10
%42 = load i8, i8* %41
%43 = call i64 @isalnum(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %10
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 45
br label %50
50: ; preds = %45, %40
%51 = phi i1 [ true, %40 ], [ %49, %45 ]
br i1 %51, label %52, label %60
52: ; preds = %50
%53 = load i8*, i8** %10
%54 = load i8, i8* %53
%55 = call signext i8 @tolower(i8 signext %54)
%56 = load i8*, i8** %10
store i8 %55, i8* %56
br label %57
57: ; preds = %52
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %10
br label %40
60: ; preds = %50
%61 = load i8*, i8** %10
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 58
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i8*, i8** %6
%67 = call i32 @error_msg_and_die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %65, %60
%69 = load i8*, i8** %10
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %10
store i8 0, i8* %69
br label %71
71: ; preds = %84, %68
%72 = load i8*, i8** %10
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 32
br i1 %75, label %81, label %76
76: ; preds = %71
%77 = load i8*, i8** %10
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp eq i32 %79, 9
br label %81
81: ; preds = %76, %71
%82 = phi i1 [ true, %71 ], [ %80, %76 ]
br i1 %82, label %83, label %87
83: ; preds = %81
br label %84
84: ; preds = %83
%85 = load i8*, i8** %10
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %10
br label %71
87: ; preds = %81
%88 = load i8*, i8** %10
store i8* %88, i8** %11
br label %89
89: ; preds = %106, %87
%90 = load i8*, i8** %10
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %104
94: ; preds = %89
%95 = load i8*, i8** %10
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp ne i32 %97, 13
br i1 %98, label %99, label %104
99: ; preds = %94
%100 = load i8*, i8** %10
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp ne i32 %102, 10
br label %104
104: ; preds = %99, %94, %89
%105 = phi i1 [ false, %94 ], [ false, %89 ], [ %103, %99 ]
br i1 %105, label %106, label %109
106: ; preds = %104
%107 = load i8*, i8** %10
%108 = getelementptr inbounds i8, i8* %107, i32 1
store i8* %108, i8** %10
br label %89
109: ; preds = %104
%110 = load i8*, i8** %10
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %109
%115 = load i8*, i8** %10
store i8 0, i8* %115
%116 = load i8*, i8** %11
store i8* %116, i8** %5
br label %133
117: ; preds = %109
br label %118
118: ; preds = %129, %117
%119 = load i32*, i32** %8
%120 = call i32 @getc(i32* %119)
store i32 %120, i32* %12
%121 = load i32, i32* %12
%122 = load i32, i32* @EOF
%123 = icmp ne i32 %121, %122
br i1 %123, label %124, label %127
124: ; preds = %118
%125 = load i32, i32* %12
%126 = icmp ne i32 %125, 10
br label %127
127: ; preds = %124, %118
%128 = phi i1 [ false, %118 ], [ %126, %124 ]
br i1 %128, label %129, label %130
129: ; preds = %127
br label %118
130: ; preds = %127
%131 = load i32*, i32** %9
store i32 1, i32* %131
%132 = load i8*, i8** %11
store i8* %132, i8** %5
br label %133
133: ; preds = %130, %114, %37, %19
%134 = load i8*, i8** %5
ret i8* %134
}

LLVM IR (-O2):
@.str = [20 x i8] c"bad header line: %s\00"
@EOF = global i32 0
define i8* @gethdr(i8* %0, i64 %1, i32* nocapture %2, i32* nocapture writeonly %3) {
store i32 0, i32* %3
%5 = tail call i32* @fgets(i8* %0, i64 %1, i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %44, label %7
7: ; preds = %4, %10
%8 = phi i8* [ %11, %10 ], [ %0, %4 ]
%9 = load i8, i8* %8
switch i8 %9, label %12 [
i8 13, label %10
i8 10, label %44
]
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
12: ; preds = %7, %19
%13 = phi i8* [ %21, %19 ], [ %0, %7 ]
%14 = load i8, i8* %13
%15 = tail call i64 @isalnum(i8 signext %14)
%16 = icmp eq i64 %15, 0
%17 = load i8, i8* %13
br i1 %16, label %18, label %19
18: ; preds = %12
switch i8 %17, label %22 [
i8 45, label %19
i8 58, label %24
]
19: ; preds = %12, %18
%20 = tail call signext i8 @tolower(i8 signext %17)
store i8 %20, i8* %13
%21 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
22: ; preds = %18
%23 = tail call i32 @error_msg_and_die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %18, %22
store i8 0, i8* %13
br label %25
25: ; preds = %29, %24
%26 = phi i8* [ %13, %24 ], [ %27, %29 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
switch i8 %28, label %30 [
i8 32, label %29
i8 9, label %29
]
29: ; preds = %25, %25
br label %25
30: ; preds = %25, %33
%31 = phi i8 [ %35, %33 ], [ %28, %25 ]
%32 = phi i8* [ %34, %33 ], [ %27, %25 ]
switch i8 %31, label %33 [
i8 0, label %37
i8 10, label %36
i8 13, label %36
]
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %32, i64 1
%35 = load i8, i8* %34
br label %30
36: ; preds = %30, %30
store i8 0, i8* %32
br label %44
37: ; preds = %30, %37
%38 = tail call i32 @getc(i32* %2)
%39 = load i32, i32* @EOF
%40 = icmp ne i32 %38, %39
%41 = icmp ne i32 %38, 10
%42 = and i1 %41, %40
br i1 %42, label %37, label %43
43: ; preds = %37
store i32 1, i32* %3
br label %44
44: ; preds = %7, %4, %43, %36
%45 = phi i8* [ %27, %36 ], [ %27, %43 ], [ null, %4 ], [ null, %7 ]
ret i8* %45
}