#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*/ freeMem(char *);
int /*<<< orphan*/ netSkipHttpHeaderLinesHandlingRedirect(int, char *, int *,
                                                          char **);
int netUrlOpen(char *);
int /*<<< orphan*/ noWarnAbort();
scalar_t__ startsWith(char *, char *);
int netUrlMustOpenPastHeader(char *url) {
  int sd = netUrlOpen(url);
  if (sd < 0)
    noWarnAbort();
  int newSd = 0;
  if (startsWith("http://", url) || startsWith("https://", url)) {
    char *newUrl = NULL;
    if (!netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl))
      noWarnAbort();
    if (newUrl != NULL) {
      sd = newSd;
      freeMem(newUrl);
    }
  }
  return sd;
}


x86 assembly (clang, -O0):
<netUrlMustOpenPastHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <netUrlOpen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1179 <netUrlMustOpenPastHeader+0x29>
mov    $0x0,%al
call   1060 <noWarnAbort@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <startsWith@plt>
cmp    $0x0,%rax
jne    11b4 <netUrlMustOpenPastHeader+0x64>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1030 <startsWith@plt>
cmp    $0x0,%rax
je     11ff <netUrlMustOpenPastHeader+0xaf>
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1070 <netSkipHttpHeaderLinesHandlingRedirect@plt>
cmp    $0x0,%eax
jne    11e0 <netUrlMustOpenPastHeader+0x90>
mov    $0x0,%al
call   1060 <noWarnAbort@plt>
cmpq   $0x0,-0x18(%rbp)
je     11fa <netUrlMustOpenPastHeader+0xaa>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <freeMem@plt>
jmp    11ff <netUrlMustOpenPastHeader+0xaf>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netUrlMustOpenPastHeader>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1050 <netUrlOpen@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    116b <netUrlMustOpenPastHeader+0x1b>
xor    %eax,%eax
call   1060 <noWarnAbort@plt>
movl   $0x0,0xc(%rsp)
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
call   1030 <startsWith@plt>
test   %rax,%rax
jne    119b <netUrlMustOpenPastHeader+0x4b>
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1030 <startsWith@plt>
test   %rax,%rax
je     11d6 <netUrlMustOpenPastHeader+0x86>
movq   $0x0,0x10(%rsp)
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <netSkipHttpHeaderLinesHandlingRedirect@plt>
test   %eax,%eax
jne    11c3 <netUrlMustOpenPastHeader+0x73>
xor    %eax,%eax
call   1060 <noWarnAbort@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     11d6 <netUrlMustOpenPastHeader+0x86>
mov    0xc(%rsp),%ebp
call   1040 <freeMem@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
define i32 @netUrlMustOpenPastHeader(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @netUrlOpen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (...) @noWarnAbort()
br label %12
12: ; preds = %10, %1
store i32 0, i32* %4
%13 = load i8*, i8** %2
%14 = call i64 @startsWith(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i64 @startsWith(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %16, %12
store i8* null, i8** %5
%21 = load i32, i32* %3
%22 = load i8*, i8** %2
%23 = call i32 @netSkipHttpHeaderLinesHandlingRedirect(i32 %21, i8* %22, i32* %4, i8** %5)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 (...) @noWarnAbort()
br label %27
27: ; preds = %25, %20
%28 = load i8*, i8** %5
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %4
store i32 %31, i32* %3
%32 = load i8*, i8** %5
%33 = call i32 @freeMem(i8* %32)
br label %34
34: ; preds = %30, %27
br label %35
35: ; preds = %34, %16
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
define i32 @netUrlMustOpenPastHeader(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = tail call i32 @netUrlOpen(i8* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (...) @noWarnAbort()
br label %8
8: ; preds = %6, %1
%9 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%10 = tail call i64 @startsWith(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i64 @startsWith(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %12, %8
%16 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%17 = call i32 @netSkipHttpHeaderLinesHandlingRedirect(i32 %4, i8* %0, i32* %2, i8** %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (...) @noWarnAbort()
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %3
%23 = icmp eq i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %2
%26 = call i32 @freeMem(i8* %22)
br label %27
27: ; preds = %24, %21
%28 = phi i32 [ %25, %24 ], [ %4, %21 ]
br label %29
29: ; preds = %27, %12
%30 = phi i32 [ %28, %27 ], [ %4, %12 ]
ret i32 %30
}