#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int dup2(int, int);
int /*<<< orphan*/ errno;
int execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int pipe(int *);
char *read_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *read_ship_url(char *url) {
  FILE *fp;
  pid_t pid;
  char *file;
  int pipefd[2];
  if (pipe(pipefd) == -1) {
    fprintf(stderr, "fight: pipe: %s\n", strerror(errno));
    return NULL;
  }
  if ((pid = fork()) > 0) {
    close(pipefd[1]);
    if ((fp = fdopen(pipefd[0], "r")) == NULL) {
      fprintf(stderr, "fight: fdopen: pipefd: failed\n");
      return NULL;
    }
  } else if (pid == 0) {
    if (dup2(pipefd[1], 1) == -1) {
      fprintf(stderr, "fight: dup2: %s\n", strerror(errno));
      return NULL;
    }
    close(pipefd[0]);
    if (execl("/usr/local/bin/GET", "GET", url, NULL) == -1) {
      fprintf(stderr, "fight: execl %s %s: %s\n", "/usr/local/bin/GET", url,
              strerror(errno));
    }
    _exit(1);
    return NULL;
  } else {
    fprintf(stderr, "fight: fork: %s\n", strerror(errno));
    return NULL;
  }
  file = read_file(fp);
  fclose(fp);
  return file;
}


x86 assembly (clang, -O0):
<read_ship_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1209 <read_ship_url+0x59>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1398 <read_ship_url+0x1e8>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jle    126c <read_ship_url+0xbc>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%edi
lea    0xde1(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1267 <read_ship_url+0xb7>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1398 <read_ship_url+0x1e8>
jmp    137a <read_ship_url+0x1ca>
cmpq   $0x0,-0x20(%rbp)
jne    133f <read_ship_url+0x18f>
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12c8 <read_ship_url+0x118>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1398 <read_ship_url+0x1e8>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdx
lea    0xd68(%rip),%rdi
lea    0xd70(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   10c0 <execl@plt>
cmp    $0xffffffff,%eax
jne    1335 <read_ship_url+0x185>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rcx
mov    %rax,%r8
lea    0xd2f(%rip),%rsi
lea    0xd15(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd08(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1398 <read_ship_url+0x1e8>
mov    -0x18(%rbp),%rdi
call   1090 <read_file@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ship_url>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     120f <read_ship_url+0x5f>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
jle    122f <read_ship_url+0x7f>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0xe27(%rip),%rsi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     1251 <read_ship_url+0xa1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <read_file@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    12ad <read_ship_url+0xfd>
mov    0x2dca(%rip),%rax
mov    (%rax),%ebx
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdd3(%rip),%rsi
jmp    129e <read_ship_url+0xee>
je     126d <read_ship_url+0xbd>
mov    0x2da8(%rip),%rax
mov    (%rax),%ebx
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe1f(%rip),%rsi
jmp    129e <read_ship_url+0xee>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12ad <read_ship_url+0xfd>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12b9 <read_ship_url+0x109>
mov    0x2d59(%rip),%rax
mov    (%rax),%ebx
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd94(%rip),%rsi
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xd7a(%rip),%rdi
lea    0xd82(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10c0 <execl@plt>
cmp    $0xffffffff,%eax
jne    1313 <read_ship_url+0x163>
mov    0x2cfa(%rip),%rax
mov    (%rax),%ebp
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd59(%rip),%rsi
lea    0xd3f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"fight: pipe: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"fight: fdopen: pipefd: failed\0A\00"
@.str.3 = [17 x i8] c"fight: dup2: %s\0A\00"
@.str.4 = [19 x i8] c"/usr/local/bin/GET\00"
@.str.5 = [4 x i8] c"GET\00"
@.str.6 = [24 x i8] c"fight: execl %s %s: %s\0A\00"
@.str.7 = [17 x i8] c"fight: fork: %s\0A\00"
define i8* @read_ship_url(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca [2 x i32]
store i8* %0, i8** %3
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
store i8* null, i8** %2
br label %70
16: ; preds = %1
%17 = call i64 (...) @fork()
store i64 %17, i64* %5
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32* @fdopen(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %4
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %70
30: ; preds = %19
br label %64
31: ; preds = %16
%32 = load i64, i64* %5
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %59
34: ; preds = %31
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @dup2(i32 %36, i32 1)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i8* null, i8** %2
br label %70
44: ; preds = %34
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
%48 = load i8*, i8** %3
%49 = call i32 @execl(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %48, i32* null)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %57
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %3
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %53, i8* %55)
br label %57
57: ; preds = %51, %44
%58 = call i32 @_exit(i32 1)
unreachable
59: ; preds = %31
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %62)
store i8* null, i8** %2
br label %70
64: ; preds = %30
%65 = load i32*, i32** %4
%66 = call i8* @read_file(i32* %65)
store i8* %66, i8** %6
%67 = load i32*, i32** %4
%68 = call i32 @fclose(i32* %67)
%69 = load i8*, i8** %6
store i8* %69, i8** %2
br label %70
70: ; preds = %64, %59, %39, %27, %11
%71 = load i8*, i8** %2
ret i8* %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"fight: pipe: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"fight: fdopen: pipefd: failed\0A\00"
@.str.3 = [17 x i8] c"fight: dup2: %s\0A\00"
@.str.4 = [19 x i8] c"/usr/local/bin/GET\00"
@.str.5 = [4 x i8] c"GET\00"
@.str.6 = [24 x i8] c"fight: execl %s %s: %s\0A\00"
@.str.7 = [17 x i8] c"fight: fork: %s\0A\00"
define i8* @read_ship_url(i8* %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %57
12: ; preds = %1
%13 = call i64 (...) @fork()
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %4
%20 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %54
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %57
25: ; preds = %12
%26 = icmp eq i64 %13, 0
br i1 %26, label %27, label %49
27: ; preds = %25
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @dup2(i32 %29, i32 1)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %57
37: ; preds = %27
%38 = load i32, i32* %4
%39 = call i32 @close(i32 %38)
%40 = call i32 @execl(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %0, i32* null)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %45)
br label %47
47: ; preds = %42, %37
%48 = call i32 @_exit(i32 1)
unreachable
49: ; preds = %25
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %52)
br label %57
54: ; preds = %15
%55 = call i8* @read_file(i32* %20)
%56 = call i32 @fclose(i32* %20)
br label %57
57: ; preds = %54, %49, %32, %22, %7
%58 = phi i8* [ null, %7 ], [ null, %22 ], [ %55, %54 ], [ null, %32 ], [ null, %49 ]
ret i8* %58
}