#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 */
struct lineFile {
  int dummy;
};
struct hash {
  int dummy;
};

/* Variables and functions */
int EIO;
int atoi(char *);
int /*<<< orphan*/ cloneString(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ hashAdd(struct hash *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
scalar_t__ isdigit(char);
struct lineFile *lineFileAttach(char *, int, int);
int /*<<< orphan*/ lineFileClose(struct lineFile **);
scalar_t__ lineFileNext(struct lineFile *, char **, int /*<<< orphan*/ *);
int netOpenHttpExt(char *, char *, int /*<<< orphan*/ *);
char *nextWord(char **);
int /*<<< orphan*/ skipLeadingSpaces(char *);
scalar_t__ startsWith(char *, char *);
int /*<<< orphan*/ strUpper(char *);
int netUrlHeadExt(char *url, char *method, struct hash *hash) {
  int sd = netOpenHttpExt(url, method, NULL);
  int status = EIO;
  if (sd >= 0) {
    char *line, *word;
    struct lineFile *lf = lineFileAttach(url, 1, sd);
    if (lineFileNext(lf, &line, NULL)) {
      if (startsWith("HTTP/", line)) {
        word = nextWord(&line);
        word = nextWord(&line);
        if (word != NULL && isdigit(word[0])) {
          status = atoi(word);
          if (hash != NULL) {
            while (lineFileNext(lf, &line, NULL)) {
              word = nextWord(&line);
              if (word == NULL)
                break;
              hashAdd(hash, strUpper(word),
                      cloneString(skipLeadingSpaces(line)));
            }
          }
        }
      }
    }
    lineFileClose(&lf);
  } else
    status = errno;
  return status;
}


x86 assembly (clang, -O0):
<netUrlHeadExt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10e0 <netOpenHttpExt@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1330 <netUrlHeadExt+0x170>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   10b0 <lineFileAttach@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <lineFileNext@plt>
cmp    $0x0,%rax
je     1322 <netUrlHeadExt+0x162>
mov    -0x28(%rbp),%rsi
lea    0xdc7(%rip),%rdi
call   1050 <startsWith@plt>
cmp    $0x0,%rax
je     131d <netUrlHeadExt+0x15d>
lea    -0x28(%rbp),%rdi
call   1090 <nextWord@plt>
mov    %rax,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
call   1090 <nextWord@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1318 <netUrlHeadExt+0x158>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1318 <netUrlHeadExt+0x158>
mov    -0x30(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1313 <netUrlHeadExt+0x153>
jmp    129f <netUrlHeadExt+0xdf>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <lineFileNext@plt>
cmp    $0x0,%rax
je     130e <netUrlHeadExt+0x14e>
lea    -0x28(%rbp),%rdi
call   1090 <nextWord@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12d7 <netUrlHeadExt+0x117>
jmp    130e <netUrlHeadExt+0x14e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <strUpper@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <skipLeadingSpaces@plt>
mov    %eax,%edi
call   1070 <cloneString@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
call   10a0 <hashAdd@plt>
jmp    129f <netUrlHeadExt+0xdf>
jmp    1313 <netUrlHeadExt+0x153>
jmp    1318 <netUrlHeadExt+0x158>
jmp    131d <netUrlHeadExt+0x15d>
jmp    1322 <netUrlHeadExt+0x162>
lea    -0x38(%rbp),%rdi
call   1030 <lineFileClose@plt>
jmp    133c <netUrlHeadExt+0x17c>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netUrlHeadExt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
xor    %edx,%edx
call   10e0 <netOpenHttpExt@plt>
test   %eax,%eax
js     12e1 <netUrlHeadExt+0x121>
mov    0x2df8(%rip),%rcx
mov    (%rcx),%r12d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   10b0 <lineFileAttach@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1080 <lineFileNext@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    (%rsp),%rsi
lea    0xddd(%rip),%rdi
call   1050 <startsWith@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1090 <nextWord@plt>
mov    %rbp,%rdi
call   1090 <nextWord@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    %rax,%rbp
movsbl (%rax),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    %rbp,%rdi
call   10d0 <atoi@plt>
mov    %eax,%r12d
test   %r14,%r14
je     12d5 <netUrlHeadExt+0x115>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <lineFileNext@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   1090 <nextWord@plt>
test   %rax,%rax
je     12d5 <netUrlHeadExt+0x115>
mov    %rax,%rdi
call   10c0 <strUpper@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   1060 <skipLeadingSpaces@plt>
mov    %eax,%edi
call   1070 <cloneString@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   10a0 <hashAdd@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <lineFileNext@plt>
test   %rax,%rax
jne    1290 <netUrlHeadExt+0xd0>
lea    0x8(%rsp),%rdi
call   1030 <lineFileClose@plt>
jmp    12eb <netUrlHeadExt+0x12b>
mov    0x2cf0(%rip),%rax
mov    (%rax),%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hash = type { i32 }
%struct.lineFile = type { i32 }
@EIO = global i32 0
@.str = [6 x i8] c"HTTP/\00"
@errno = global i32 0
define i32 @netUrlHeadExt(i8* %0, i8* %1, %struct.hash* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.hash*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.lineFile*
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.hash* %2, %struct.hash** %6
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @netOpenHttpExt(i8* %12, i8* %13, i32* null)
store i32 %14, i32* %7
%15 = load i32, i32* @EIO
store i32 %15, i32* %8
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %69
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = call %struct.lineFile* @lineFileAttach(i8* %19, i32 1, i32 %20)
store %struct.lineFile* %21, %struct.lineFile** %11
%22 = load %struct.lineFile*, %struct.lineFile** %11
%23 = call i64 @lineFileNext(%struct.lineFile* %22, i8** %9, i32* null)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %67
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = call i64 @startsWith(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %66
29: ; preds = %25
%30 = call i8* @nextWord(i8** %9)
store i8* %30, i8** %10
%31 = call i8* @nextWord(i8** %9)
store i8* %31, i8** %10
%32 = load i8*, i8** %10
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %65
34: ; preds = %29
%35 = load i8*, i8** %10
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = call i64 @isdigit(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %65
40: ; preds = %34
%41 = load i8*, i8** %10
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %8
%43 = load %struct.hash*, %struct.hash** %6
%44 = icmp ne %struct.hash* %43, null
br i1 %44, label %45, label %64
45: ; preds = %40
br label %46
46: ; preds = %55, %45
%47 = load %struct.lineFile*, %struct.lineFile** %11
%48 = call i64 @lineFileNext(%struct.lineFile* %47, i8** %9, i32* null)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = call i8* @nextWord(i8** %9)
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %55
54: ; preds = %50
br label %63
55: ; preds = %50
%56 = load %struct.hash*, %struct.hash** %6
%57 = load i8*, i8** %10
%58 = call i32 @strUpper(i8* %57)
%59 = load i8*, i8** %9
%60 = call i32 @skipLeadingSpaces(i8* %59)
%61 = call i32 @cloneString(i32 %60)
%62 = call i32 @hashAdd(%struct.hash* %56, i32 %58, i32 %61)
br label %46
63: ; preds = %54, %46
br label %64
64: ; preds = %63, %40
br label %65
65: ; preds = %64, %34, %29
br label %66
66: ; preds = %65, %25
br label %67
67: ; preds = %66, %18
%68 = call i32 @lineFileClose(%struct.lineFile** %11)
br label %71
69: ; preds = %3
%70 = load i32, i32* @errno
store i32 %70, i32* %8
br label %71
71: ; preds = %69, %67
%72 = load i32, i32* %8
ret i32 %72
}

LLVM IR (-O2):
%struct.hash = type { i32 }
%struct.lineFile = type { i32 }
@EIO = global i32 0
@.str = [6 x i8] c"HTTP/\00"
@errno = global i32 0
define i32 @netUrlHeadExt(i8* %0, i8* %1, %struct.hash* %2) {
%4 = alloca i8*
%5 = alloca %struct.lineFile*
%6 = tail call i32 @netOpenHttpExt(i8* %0, i8* %1, i32* null)
%7 = load i32, i32* @EIO
%8 = icmp sgt i32 %6, -1
br i1 %8, label %9, label %47
9: ; preds = %3
%10 = bitcast i8** %4 to i8*
%11 = bitcast %struct.lineFile** %5 to i8*
%12 = tail call %struct.lineFile* @lineFileAttach(i8* %0, i32 1, i32 %6)
store %struct.lineFile* %12, %struct.lineFile** %5
%13 = call i64 @lineFileNext(%struct.lineFile* %12, i8** %4, i32* null)
%14 = icmp eq i64 %13, 0
br i1 %14, label %44, label %15
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = call i64 @startsWith(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %44, label %19
19: ; preds = %15
%20 = call i8* @nextWord(i8** %4)
%21 = call i8* @nextWord(i8** %4)
%22 = icmp eq i8* %21, null
br i1 %22, label %44, label %23
23: ; preds = %19
%24 = load i8, i8* %21
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %44, label %27
27: ; preds = %23
%28 = call i32 @atoi(i8* %21)
%29 = icmp eq %struct.hash* %2, null
br i1 %29, label %44, label %30
30: ; preds = %27
%31 = call i64 @lineFileNext(%struct.lineFile* %12, i8** %4, i32* null)
%32 = icmp eq i64 %31, 0
br i1 %32, label %44, label %33
33: ; preds = %30, %36
%34 = call i8* @nextWord(i8** %4)
%35 = icmp eq i8* %34, null
br i1 %35, label %44, label %36
36: ; preds = %33
%37 = call i32 @strUpper(i8* %34)
%38 = load i8*, i8** %4
%39 = call i32 @skipLeadingSpaces(i8* %38)
%40 = call i32 @cloneString(i32 %39)
%41 = call i32 @hashAdd(%struct.hash* %2, i32 %37, i32 %40)
%42 = call i64 @lineFileNext(%struct.lineFile* %12, i8** %4, i32* null)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %33
44: ; preds = %36, %33, %30, %15, %27, %23, %19, %9
%45 = phi i32 [ %28, %27 ], [ %7, %23 ], [ %7, %19 ], [ %7, %15 ], [ %7, %9 ], [ %28, %30 ], [ %28, %33 ], [ %28, %36 ]
%46 = call i32 @lineFileClose(%struct.lineFile** %5)
br label %49
47: ; preds = %3
%48 = load i32, i32* @errno
br label %49
49: ; preds = %47, %44
%50 = phi i32 [ %45, %44 ], [ %48, %47 ]
ret i32 %50
}