#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;
};

/* Variables and functions */
int /*<<< orphan*/ cgiDecode(char *, char *, int /*<<< orphan*/);
char *cloneString(char *);
scalar_t__ endsWith(char *, char *);
int /*<<< orphan*/ freeMem(char *);
struct lineFile *lineFileAttach(char *, int, int);
struct lineFile *lineFileDecompressFd(char *, int, int);
int /*<<< orphan*/ netSkipHttpHeaderLinesHandlingRedirect(int, char *, int *,
                                                          char **);
int netUrlOpen(char *);
scalar_t__ startsWith(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ warn(char *, char *);
struct lineFile *netLineFileMayOpen(char *url) {
  int sd = netUrlOpen(url);
  if (sd < 0) {
    warn("Couldn't open %s", url);
    return NULL;
  } else {
    struct lineFile *lf = NULL;
    char *newUrl = NULL;
    int newSd = 0;
    if (startsWith("http://", url) || startsWith("https://", url)) {
      if (!netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl)) {
        return NULL;
      }
      if (newUrl != NULL) {
        sd = newSd;
        url = newUrl;
      }
    }
    char *urlDecoded = cloneString(url);
    cgiDecode(url, urlDecoded, strlen(url));
    int isCompressed =
        (endsWith(urlDecoded, ".gz") || endsWith(urlDecoded, ".Z") ||
         endsWith(urlDecoded, ".bz2"));
    freeMem(urlDecoded);
    if (isCompressed) {
      lf = lineFileDecompressFd(url, 1, sd);
    } else {
      lf = lineFileAttach(url, 1, sd);
    }
    if (newUrl)
      freeMem(newUrl);
    return lf;
  }
}


x86 assembly (clang, -O0):
<netLineFileMayOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <netUrlOpen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ef <netLineFileMayOpen+0x3f>
mov    -0x10(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1030 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    137e <netLineFileMayOpen+0x1ce>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1040 <startsWith@plt>
cmp    $0x0,%rax
jne    123a <netLineFileMayOpen+0x8a>
mov    -0x10(%rbp),%rsi
lea    0xdee(%rip),%rdi
call   1040 <startsWith@plt>
cmp    $0x0,%rax
je     1282 <netLineFileMayOpen+0xd2>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1090 <netSkipHttpHeaderLinesHandlingRedirect@plt>
cmp    $0x0,%eax
jne    1264 <netLineFileMayOpen+0xb4>
movq   $0x0,-0x8(%rbp)
jmp    137e <netLineFileMayOpen+0x1ce>
cmpq   $0x0,-0x28(%rbp)
je     127d <netLineFileMayOpen+0xcd>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1282 <netLineFileMayOpen+0xd2>
mov    -0x10(%rbp),%rdi
call   1080 <cloneString@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   10c0 <cgiDecode@plt>
mov    -0x38(%rbp),%rdi
lea    0xd60(%rip),%rsi
call   10b0 <endsWith@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x3d(%rbp)
jne    1315 <netLineFileMayOpen+0x165>
mov    -0x38(%rbp),%rdi
lea    0xd42(%rip),%rsi
call   10b0 <endsWith@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x3d(%rbp)
jne    1315 <netLineFileMayOpen+0x165>
mov    -0x38(%rbp),%rdi
lea    0xd23(%rip),%rsi
call   10b0 <endsWith@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <freeMem@plt>
cmpl   $0x0,-0x3c(%rbp)
je     134d <netLineFileMayOpen+0x19d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   10d0 <lineFileDecompressFd@plt>
mov    %rax,-0x20(%rbp)
jmp    1362 <netLineFileMayOpen+0x1b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   10a0 <lineFileAttach@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1376 <netLineFileMayOpen+0x1c6>
mov    -0x28(%rbp),%rdi
call   1060 <freeMem@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netLineFileMayOpen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1070 <netUrlOpen@plt>
test   %eax,%eax
js     12a9 <netLineFileMayOpen+0xf9>
mov    %eax,%r14d
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
call   1040 <startsWith@plt>
test   %rax,%rax
jne    1206 <netLineFileMayOpen+0x56>
lea    0xe20(%rip),%rdi
mov    %rbx,%rsi
call   1040 <startsWith@plt>
test   %rax,%rax
je     1235 <netLineFileMayOpen+0x85>
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1090 <netSkipHttpHeaderLinesHandlingRedirect@plt>
test   %eax,%eax
je     12b8 <netLineFileMayOpen+0x108>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1235 <netLineFileMayOpen+0x85>
mov    0xc(%rsp),%r14d
mov    %rax,%rbx
mov    %rbx,%rdi
call   1080 <cloneString@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   10c0 <cgiDecode@plt>
lea    0xdc6(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <endsWith@plt>
test   %rax,%rax
jne    127d <netLineFileMayOpen+0xcd>
lea    0xdb6(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <endsWith@plt>
test   %rax,%rax
je     12c8 <netLineFileMayOpen+0x118>
mov    %rbp,%rdi
call   1060 <freeMem@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   10d0 <lineFileDecompressFd@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     12ba <netLineFileMayOpen+0x10a>
call   1060 <freeMem@plt>
jmp    12ba <netLineFileMayOpen+0x10a>
lea    0xd50(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5a(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <endsWith@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1060 <freeMem@plt>
test   %r15,%r15
jne    1285 <netLineFileMayOpen+0xd5>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   10a0 <lineFileAttach@plt>
jmp    1295 <netLineFileMayOpen+0xe5>

LLVM IR (-O0):
%struct.lineFile = type { i32 }
@.str = [17 x i8] c"Couldn't open %s\00"
@.str.1 = [8 x i8] c"http://\00"
@.str.2 = [9 x i8] c"https://\00"
@.str.3 = [4 x i8] c".gz\00"
@.str.4 = [3 x i8] c".Z\00"
@.str.5 = [5 x i8] c".bz2\00"
define %struct.lineFile* @netLineFileMayOpen(i8* %0) {
%2 = alloca %struct.lineFile*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.lineFile*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @netUrlOpen(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @warn(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
store %struct.lineFile* null, %struct.lineFile** %2
br label %80
17: ; preds = %1
store %struct.lineFile* null, %struct.lineFile** %5
store i8* null, i8** %6
store i32 0, i32* %7
%18 = load i8*, i8** %3
%19 = call i64 @startsWith(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i64 @startsWith(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %21, %17
%26 = load i32, i32* %4
%27 = load i8*, i8** %3
%28 = call i32 @netSkipHttpHeaderLinesHandlingRedirect(i32 %26, i8* %27, i32* %7, i8** %6)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store %struct.lineFile* null, %struct.lineFile** %2
br label %80
31: ; preds = %25
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %7
store i32 %35, i32* %4
%36 = load i8*, i8** %6
store i8* %36, i8** %3
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %21
%39 = load i8*, i8** %3
%40 = call i8* @cloneString(i8* %39)
store i8* %40, i8** %8
%41 = load i8*, i8** %3
%42 = load i8*, i8** %8
%43 = load i8*, i8** %3
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @cgiDecode(i8* %41, i8* %42, i32 %44)
%46 = load i8*, i8** %8
%47 = call i64 @endsWith(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp ne i64 %47, 0
br i1 %48, label %57, label %49
49: ; preds = %38
%50 = load i8*, i8** %8
%51 = call i64 @endsWith(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp ne i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = load i8*, i8** %8
%55 = call i64 @endsWith(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%56 = icmp ne i64 %55, 0
br label %57
57: ; preds = %53, %49, %38
%58 = phi i1 [ true, %49 ], [ true, %38 ], [ %56, %53 ]
%59 = zext i1 %58 to i32
store i32 %59, i32* %9
%60 = load i8*, i8** %8
%61 = call i32 @freeMem(i8* %60)
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = load i8*, i8** %3
%66 = load i32, i32* %4
%67 = call %struct.lineFile* @lineFileDecompressFd(i8* %65, i32 1, i32 %66)
store %struct.lineFile* %67, %struct.lineFile** %5
br label %72
68: ; preds = %57
%69 = load i8*, i8** %3
%70 = load i32, i32* %4
%71 = call %struct.lineFile* @lineFileAttach(i8* %69, i32 1, i32 %70)
store %struct.lineFile* %71, %struct.lineFile** %5
br label %72
72: ; preds = %68, %64
%73 = load i8*, i8** %6
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i8*, i8** %6
%77 = call i32 @freeMem(i8* %76)
br label %78
78: ; preds = %75, %72
%79 = load %struct.lineFile*, %struct.lineFile** %5
store %struct.lineFile* %79, %struct.lineFile** %2
br label %80
80: ; preds = %78, %30, %14
%81 = load %struct.lineFile*, %struct.lineFile** %2
ret %struct.lineFile* %81
}

LLVM IR (-O2):
%struct.lineFile = type { i32 }
@.str = [17 x i8] c"Couldn't open %s\00"
@.str.1 = [8 x i8] c"http://\00"
@.str.2 = [9 x i8] c"https://\00"
@.str.3 = [4 x i8] c".gz\00"
@.str.4 = [3 x i8] c".Z\00"
@.str.5 = [5 x i8] c".bz2\00"
define %struct.lineFile* @netLineFileMayOpen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%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 @warn(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %54
8: ; preds = %1
%9 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = tail call i64 @startsWith(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i64 @startsWith(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13, %8
%17 = call i32 @netSkipHttpHeaderLinesHandlingRedirect(i32 %4, i8* %0, i32* %3, i8** %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %52, label %19
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = icmp eq i8* %20, null
%22 = load i32, i32* %3
%23 = select i1 %21, i32 %4, i32 %22
%24 = select i1 %21, i8* %0, i8* %20
br label %25
25: ; preds = %19, %13
%26 = phi i32 [ %4, %13 ], [ %23, %19 ]
%27 = phi i8* [ %0, %13 ], [ %24, %19 ]
%28 = call i8* @cloneString(i8* %27)
%29 = call i32 @strlen(i8* %27)
%30 = call i32 @cgiDecode(i8* %27, i8* %28, i32 %29)
%31 = call i64 @endsWith(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = call i64 @endsWith(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = call i64 @endsWith(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = call i32 @freeMem(i8* %28)
br i1 %38, label %44, label %42
40: ; preds = %25, %33
%41 = call i32 @freeMem(i8* %28)
br label %42
42: ; preds = %40, %36
%43 = call %struct.lineFile* @lineFileDecompressFd(i8* %27, i32 1, i32 %26)
br label %46
44: ; preds = %36
%45 = call %struct.lineFile* @lineFileAttach(i8* %27, i32 1, i32 %26)
br label %46
46: ; preds = %44, %42
%47 = phi %struct.lineFile* [ %43, %42 ], [ %45, %44 ]
%48 = load i8*, i8** %2
%49 = icmp eq i8* %48, null
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 @freeMem(i8* %48)
br label %52
52: ; preds = %46, %50, %16
%53 = phi %struct.lineFile* [ null, %16 ], [ %47, %50 ], [ %47, %46 ]
br label %54
54: ; preds = %52, %6
%55 = phi %struct.lineFile* [ null, %6 ], [ %53, %52 ]
ret %struct.lineFile* %55
}