#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ gets(char *);
int /*<<< orphan*/ http_error(int);
int http_rman(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ system(char *);
int main(int ac, char **av) {
  char buf[200];
  char url[200];
  int status;
  char *sFrontpage = "/usr/local/lib/rman/http-rman.html";
  if (ac > 1)
    sFrontpage = av[1];
  if (gets(buf)) {
    while (gets(url) && url[0] != '\r')
      ;
    if (sscanf(buf, "GET %s", url) == 1) {
      status = http_rman(url);
      if (status < 0) {
        sprintf(buf, "cat %s", sFrontpage);
        if (system(buf) == 0)
          status = 0;
      }
      if (status < 0)
        http_error(404);
    } else
      http_error(400);
  }
  fflush(stdout);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x1c0(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x1c0(%rbp)
lea    -0xe0(%rbp),%rdi
call   1060 <gets@plt>
cmp    $0x0,%rax
je     12d3 <main+0x153>
jmp    11db <main+0x5b>
lea    -0x1b0(%rbp),%rdi
call   1060 <gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1c1(%rbp)
je     120f <main+0x8f>
movsbl -0x1b0(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x1c1(%rbp)
mov    -0x1c1(%rbp),%al
test   $0x1,%al
jne    1222 <main+0xa2>
jmp    1227 <main+0xa7>
jmp    11db <main+0x5b>
lea    -0xe0(%rbp),%rdi
lea    -0x1b0(%rbp),%rdx
lea    0xde7(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    12c4 <main+0x144>
lea    -0x1b0(%rbp),%rdi
call   1050 <http_rman@plt>
mov    %eax,-0x1b4(%rbp)
cmpl   $0x0,-0x1b4(%rbp)
jge    12a8 <main+0x128>
lea    -0xe0(%rbp),%rdi
mov    -0x1c0(%rbp),%rdx
lea    0xdac(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
jne    12a3 <main+0x123>
movl   $0x0,-0x1b4(%rbp)
jmp    12a8 <main+0x128>
cmpl   $0x0,-0x1b4(%rbp)
jge    12bf <main+0x13f>
mov    $0x194,%edi
call   1040 <http_error@plt>
jmp    12ce <main+0x14e>
mov    $0x190,%edi
call   1040 <http_error@plt>
jmp    12d3 <main+0x153>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x198,%rsp
cmp    $0x2,%edi
jl     1195 <main+0x15>
mov    0x8(%rsi),%r14
jmp    119c <main+0x1c>
lea    0xe64(%rip),%r14
lea    0xd0(%rsp),%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     1231 <main+0xb1>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     11d3 <main+0x53>
cmpb   $0xd,(%rsp)
jne    11c0 <main+0x40>
lea    0xe49(%rip),%rsi
lea    0xd0(%rsp),%rdi
mov    %rsp,%rdx
call   1080 <sscanf@plt>
mov    $0x190,%edi
cmp    $0x1,%eax
jne    122c <main+0xac>
mov    %rsp,%rdi
call   1050 <http_rman@plt>
test   %eax,%eax
jns    1231 <main+0xb1>
lea    0xe23(%rip),%rsi
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    $0x194,%edi
test   %rax,%rax
je     1231 <main+0xb1>
call   1040 <http_error@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"/usr/local/lib/rman/http-rman.html\00"
@.str.1 = [7 x i8] c"GET %s\00"
@.str.2 = [7 x i8] c"cat %s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [200 x i8]
%7 = alloca [200 x i8]
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %9
br label %16
16: ; preds = %12, %2
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%18 = call i64 @gets(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %61
20: ; preds = %16
br label %21
21: ; preds = %32, %20
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%23 = call i64 @gets(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 13
br label %30
30: ; preds = %25, %21
%31 = phi i1 [ false, %21 ], [ %29, %25 ]
br i1 %31, label %32, label %33
32: ; preds = %30
br label %21
33: ; preds = %30
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%36 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %58
38: ; preds = %33
%39 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%40 = call i32 @http_rman(i8* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %38
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%45 = load i8*, i8** %9
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%48 = call i64 @system(i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %43
store i32 0, i32* %8
br label %51
51: ; preds = %50, %43
br label %52
52: ; preds = %51, %38
%53 = load i32, i32* %8
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @http_error(i32 404)
br label %57
57: ; preds = %55, %52
br label %60
58: ; preds = %33
%59 = call i32 @http_error(i32 400)
br label %60
60: ; preds = %58, %57
br label %61
61: ; preds = %60, %16
%62 = load i32, i32* @stdout
%63 = call i32 @fflush(i32 %62)
%64 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [35 x i8] c"/usr/local/lib/rman/http-rman.html\00"
@.str.1 = [7 x i8] c"GET %s\00"
@.str.2 = [7 x i8] c"cat %s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %8, %2
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = call i64 @gets(i8* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %34, label %15
15: ; preds = %11, %15
%16 = call i64 @gets(i8* %6)
%17 = icmp ne i64 %16, 0
%18 = load i8, i8* %6
%19 = icmp ne i8 %18, 13
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %15, label %21
21: ; preds = %15
%22 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = call i32 @http_rman(i8* %6)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%29 = call i64 @system(i8* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %21, %27
%32 = phi i32 [ 404, %27 ], [ 400, %21 ]
%33 = call i32 @http_error(i32 %32)
br label %34
34: ; preds = %31, %27, %24, %11
%35 = load i32, i32* @stdout
%36 = call i32 @fflush(i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
}