#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ save_req(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ send_res(int, int /*<<< orphan*/ *);
int serve(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct st;
  int conn;
  FILE *req, *res;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s output-filename port response\n", argv[0]);
    exit(1);
  }
  if (!(req = fopen(argv[1], "w"))) {
    fprintf(stderr, "Unable to open output file \"%s\": %s\n", argv[1],
            strerror(errno));
    exit(1);
  }
  if (!(res = fopen(argv[3], "r"))) {
    fprintf(stderr, "Unable to open response \"%s\": %s\n", argv[3],
            strerror(errno));
    exit(1);
  }
  conn = serve("/tmp/fakehttp.pid", argv[2]);
  save_req(conn, req);
  send_res(conn, res);
  close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11c8 <main+0x48>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1232 <main+0xb2>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    129c <main+0x11c>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdc9(%rip),%rdi
call   1050 <serve@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <save_req@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <send_res@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x4,%edi
jne    11fd <main+0x7d>
mov    0x8(%r15),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1221 <main+0xa1>
mov    %rax,%r14
mov    0x18(%r15),%rdi
lea    0xe9e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1245 <main+0xc5>
mov    %rax,%rbx
mov    0x10(%r15),%rsi
lea    0xea6(%rip),%rdi
call   1050 <serve@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <save_req@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_res@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r15),%r14
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xde8(%rip),%rsi
jmp    1267 <main+0xe7>
mov    0x2d94(%rip),%rax
mov    (%rax),%ebx
mov    0x18(%r15),%r14
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdeb(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s output-filename port response\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [37 x i8] c"Unable to open output file \22%s\22: %s\0A\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [34 x i8] c"Unable to open response \22%s\22: %s\0A\00"
@.str.5 = [18 x i8] c"/tmp/fakehttp.pid\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %33, label %24
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %48, label %39
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %43, i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %33
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @serve(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = load i32*, i32** %7
%55 = call i32 @save_req(i32 %53, i32* %54)
%56 = load i32, i32* %6
%57 = load i32*, i32** %8
%58 = call i32 @send_res(i32 %56, i32* %57)
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s output-filename port response\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [37 x i8] c"Unable to open output file \22%s\22: %s\0A\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [34 x i8] c"Unable to open response \22%s\22: %s\0A\00"
@.str.5 = [18 x i8] c"/tmp/fakehttp.pid\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %22
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %28, i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i32 @serve(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = tail call i32 @save_req(i32 %36, i32* %12)
%38 = tail call i32 @send_res(i32 %36, i32* %24)
%39 = tail call i32 @close(i32 %36)
ret i32 0
}