#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*/ BIO;

/* Variables and functions */
int BIO_FP_TEXT;
int BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
long strtol(char *, char **, int);
int write_proxy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ *, int /*<<< orphan*/ *, long);
int main(int argc, char **argv) {
  BIO *bio_stdin = NULL;
  BIO *bio_stdout = NULL;
  BIO *bio_stderr = NULL;
  int rval = EXIT_FAILURE;
  long hours = 0;
  char *endptr = "\1";
  if (argc == 1) {
    hours = 1;
  } else if (argc == 2) {
    hours = strtol(argv[1], &endptr, 10);
    if (*endptr != '\0') {
      fprintf(stderr, "Usage: %s [lifetime in hours]\n", argv[0]);
      return EXIT_FAILURE;
    }
  } else {
    fprintf(stderr, "Usage: %s [lifetime in hours]\n", argv[0]);
    return EXIT_FAILURE;
  }
  if ((bio_stdin = BIO_new(BIO_s_file())) == NULL) {
    fprintf(stderr, "Failed to allocate bio_stdin\n");
    goto end;
  }
  if ((bio_stdout = BIO_new(BIO_s_file())) == NULL) {
    fprintf(stderr, "Failed to allocate bio_stdout\n");
    goto end;
  }
  if ((bio_stderr = BIO_new(BIO_s_file())) == NULL) {
    fprintf(stderr, "Failed to allocate bio_stderr\n");
    goto end;
  }
  BIO_set_fp(bio_stdin, stdin, BIO_NOCLOSE);
  BIO_set_fp(bio_stdout, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
  BIO_set_fp(bio_stderr, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
  rval = write_proxy(bio_stdin, bio_stdin, bio_stdout, bio_stderr, hours);
end:
  if (bio_stdin != NULL)
    BIO_free(bio_stdin);
  if (bio_stdout != NULL)
    BIO_free(bio_stdout);
  if (bio_stderr != NULL)
    BIO_free(bio_stderr);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d4 <main+0x64>
movq   $0x1,-0x38(%rbp)
jmp    1270 <main+0x100>
cmpl   $0x2,-0x8(%rbp)
jne    123c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1237 <main+0xc7>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13df <main+0x26f>
jmp    126b <main+0xfb>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13df <main+0x26f>
jmp    1270 <main+0x100>
mov    $0x0,%al
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12a8 <main+0x138>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1397 <main+0x227>
mov    $0x0,%al
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12e0 <main+0x170>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1397 <main+0x227>
mov    $0x0,%al
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1318 <main+0x1a8>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1397 <main+0x227>
mov    -0x18(%rbp),%rdi
mov    0x2cbd(%rip),%rax
mov    (%rax),%esi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
call   1080 <BIO_set_fp@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
mov    0x2c88(%rip),%rax
or     (%rax),%edx
call   1080 <BIO_set_fp@plt>
mov    -0x28(%rbp),%rdi
mov    0x2c66(%rip),%rax
mov    (%rax),%esi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edx
mov    0x2c64(%rip),%rax
or     (%rax),%edx
call   1080 <BIO_set_fp@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1030 <write_proxy@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     13ab <main+0x23b>
mov    -0x18(%rbp),%rdi
call   1070 <BIO_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     13bf <main+0x24f>
mov    -0x20(%rbp),%rdi
call   1070 <BIO_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     13d3 <main+0x263>
mov    -0x28(%rbp),%rdi
call   1070 <BIO_free@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rax
mov    %rax,(%rsp)
cmp    $0x1,%edi
je     11d6 <main+0x66>
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11b0 <main+0x40>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11dc <main+0x6c>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2def(%rip),%rbx
jmp    1316 <main+0x1a6>
mov    $0x1,%r14d
xor    %eax,%eax
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
test   %rax,%rax
je     1293 <main+0x123>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
test   %rax,%rax
je     12b3 <main+0x143>
mov    %rax,%r15
xor    %eax,%eax
call   1090 <BIO_s_file@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,%r12
test   %rax,%rax
je     12db <main+0x16b>
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%r13
mov    0x0(%r13),%edx
mov    %rbx,%rdi
call   1080 <BIO_set_fp@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rbp
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    %r15,%rdi
call   1080 <BIO_set_fp@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    %r12,%rdi
call   1080 <BIO_set_fp@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1030 <write_proxy@plt>
jmp    12f2 <main+0x182>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2cff(%rip),%rbx
jmp    1316 <main+0x1a6>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <BIO_free@plt>
mov    0x2cd7(%rip),%rbx
jmp    1316 <main+0x1a6>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <BIO_free@plt>
mov    %r15,%rdi
call   1070 <BIO_free@plt>
mov    0x2ca7(%rip),%rbx
test   %r12,%r12
je     1316 <main+0x1a6>
mov    %r12,%rdi
call   1070 <BIO_free@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"\01\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Usage: %s [lifetime in hours]\0A\00"
@.str.2 = [30 x i8] c"Failed to allocate bio_stdin\0A\00"
@.str.3 = [31 x i8] c"Failed to allocate bio_stdout\0A\00"
@.str.4 = [31 x i8] c"Failed to allocate bio_stderr\0A\00"
@stdin = global i32 0
@BIO_NOCLOSE = global i32 0
@stdout = global i32 0
@BIO_FP_TEXT = global i32 0
@EXIT_SUCCESS = global i32 0
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*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32* null, i32** %8
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %9
store i64 0, i64* %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %2
store i64 1, i64* %10
br label %44
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strtol(i8* %22, i8** %11, i32 10)
store i64 %23, i64* %10
%24 = load i8*, i8** %11
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %3
br label %108
35: ; preds = %19
br label %43
36: ; preds = %16
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %108
43: ; preds = %35
br label %44
44: ; preds = %43, %15
%45 = call i32 (...) @BIO_s_file()
%46 = call i32* @BIO_new(i32 %45)
store i32* %46, i32** %6
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %88
51: ; preds = %44
%52 = call i32 (...) @BIO_s_file()
%53 = call i32* @BIO_new(i32 %52)
store i32* %53, i32** %7
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %88
58: ; preds = %51
%59 = call i32 (...) @BIO_s_file()
%60 = call i32* @BIO_new(i32 %59)
store i32* %60, i32** %8
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %88
65: ; preds = %58
%66 = load i32*, i32** %6
%67 = load i32, i32* @stdin
%68 = load i32, i32* @BIO_NOCLOSE
%69 = call i32 @BIO_set_fp(i32* %66, i32 %67, i32 %68)
%70 = load i32*, i32** %7
%71 = load i32, i32* @stdout
%72 = load i32, i32* @BIO_NOCLOSE
%73 = load i32, i32* @BIO_FP_TEXT
%74 = or i32 %72, %73
%75 = call i32 @BIO_set_fp(i32* %70, i32 %71, i32 %74)
%76 = load i32*, i32** %8
%77 = load i32, i32* @stderr
%78 = load i32, i32* @BIO_NOCLOSE
%79 = load i32, i32* @BIO_FP_TEXT
%80 = or i32 %78, %79
%81 = call i32 @BIO_set_fp(i32* %76, i32 %77, i32 %80)
%82 = load i32*, i32** %6
%83 = load i32*, i32** %6
%84 = load i32*, i32** %7
%85 = load i32*, i32** %8
%86 = load i64, i64* %10
%87 = call i32 @write_proxy(i32* %82, i32* %83, i32* %84, i32* %85, i64 %86)
store i32 %87, i32* %9
br label %88
88: ; preds = %65, %62, %55, %48
%89 = load i32*, i32** %6
%90 = icmp ne i32* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32*, i32** %6
%93 = call i32 @BIO_free(i32* %92)
br label %94
94: ; preds = %91, %88
%95 = load i32*, i32** %7
%96 = icmp ne i32* %95, null
br i1 %96, label %97, label %100
97: ; preds = %94
%98 = load i32*, i32** %7
%99 = call i32 @BIO_free(i32* %98)
br label %100
100: ; preds = %97, %94
%101 = load i32*, i32** %8
%102 = icmp ne i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32*, i32** %8
%105 = call i32 @BIO_free(i32* %104)
br label %106
106: ; preds = %103, %100
%107 = load i32, i32* @EXIT_SUCCESS
store i32 %107, i32* %3
br label %108
108: ; preds = %106, %36, %28
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"\01\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Usage: %s [lifetime in hours]\0A\00"
@.str.2 = [30 x i8] c"Failed to allocate bio_stdin\0A\00"
@.str.3 = [31 x i8] c"Failed to allocate bio_stdout\0A\00"
@.str.4 = [31 x i8] c"Failed to allocate bio_stderr\0A\00"
@stdin = global i32 0
@BIO_NOCLOSE = global i32 0
@stdout = global i32 0
@BIO_FP_TEXT = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
switch i32 %0, label %16 [
i32 1, label %20
i32 2, label %5
]
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = call i64 @strtol(i8* %7, i8** %3, i32 10)
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %63
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %63
20: ; preds = %2, %5
%21 = phi i64 [ %8, %5 ], [ 1, %2 ]
%22 = tail call i32 (...) @BIO_s_file()
%23 = tail call i32* @BIO_new(i32 %22)
%24 = icmp eq i32* %23, null
br i1 %24, label %51, label %25
25: ; preds = %20
%26 = tail call i32 (...) @BIO_s_file()
%27 = tail call i32* @BIO_new(i32 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %54, label %29
29: ; preds = %25
%30 = tail call i32 (...) @BIO_s_file()
%31 = tail call i32* @BIO_new(i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %58
36: ; preds = %29
%37 = load i32, i32* @stdin
%38 = load i32, i32* @BIO_NOCLOSE
%39 = tail call i32 @BIO_set_fp(i32* %23, i32 %37, i32 %38)
%40 = load i32, i32* @stdout
%41 = load i32, i32* @BIO_NOCLOSE
%42 = load i32, i32* @BIO_FP_TEXT
%43 = or i32 %42, %41
%44 = tail call i32 @BIO_set_fp(i32* %27, i32 %40, i32 %43)
%45 = load i32, i32* @stderr
%46 = load i32, i32* @BIO_NOCLOSE
%47 = load i32, i32* @BIO_FP_TEXT
%48 = or i32 %47, %46
%49 = tail call i32 @BIO_set_fp(i32* %31, i32 %45, i32 %48)
%50 = tail call i32 @write_proxy(i32* %23, i32* %23, i32* %27, i32* %31, i64 %21)
br label %58
51: ; preds = %20
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %63
54: ; preds = %25
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%57 = tail call i32 @BIO_free(i32* %23)
br label %63
58: ; preds = %33, %36
%59 = tail call i32 @BIO_free(i32* %23)
%60 = tail call i32 @BIO_free(i32* %27)
br i1 %32, label %63, label %61
61: ; preds = %58
%62 = tail call i32 @BIO_free(i32* %31)
br label %63
63: ; preds = %54, %51, %58, %61, %16, %12
%64 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %61 ], [ @EXIT_SUCCESS, %58 ], [ @EXIT_SUCCESS, %51 ], [ @EXIT_SUCCESS, %54 ]
%65 = load i32, i32* %64
ret i32 %65
}