#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*/ username;
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ session_id;
typedef int /*<<< orphan*/ protocol_version;
typedef int /*<<< orphan*/ password;

/* Variables and functions */
int copy_env(char *, char *, int);
int /*<<< orphan*/ do_auth(char *, char *, char *);
int do_special_invocation(int, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_content_length();
int /*<<< orphan*/ init_settings_from_env();
int /*<<< orphan*/ is_method_post();
int /*<<< orphan*/ make_datadir();
int respond(int, char *);
int /*<<< orphan*/ save_incoming_data(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (!init_settings_from_env()) {
    fprintf(stderr, "Exiting due to missing or invalid settings.\n");
    return respond(500, "Internal Server Error");
  }
  int special_status = do_special_invocation(argc, argv);
  if (special_status == 1) {
    return respond(200, "OK");
  } else if (special_status == 0) {
    return respond(500, "Internal Server Error");
  }
  if (!is_method_post()) {
    fprintf(stderr, "Not a POST request.\n");
    return respond(405, "Method Not Allowed");
  }
  ssize_t content_length = get_content_length();
  char protocol_version[16];
  if (!copy_env("HTTP_X_TMC_VERSION", protocol_version,
                sizeof(protocol_version))) {
    fprintf(stderr, "Protocol version missing or too long.\n");
    return respond(400, "Bad Request");
  }
  if (strcmp(protocol_version, "1") != 0) {
    fprintf(stderr, "Unknown protocol version.\n");
    return respond(400, "Bad Request");
  }
  char username[256];
  if (!copy_env("HTTP_X_TMC_USERNAME", username, sizeof(username))) {
    fprintf(stderr, "Username missing or too long.\n");
    return respond(400, "Bad Request");
  }
  if (username[0] == '.') {
    fprintf(stderr, "Username starts with '.'.\n");
    return respond(400, "Bad Request");
  }
  if (strchr(username, '/')) {
    fprintf(stderr, "Username contains a '/'.\n");
    return respond(400, "Bad Request");
  }
  char password[256];
  char session_id[256];
  int got_password =
      copy_env("HTTP_X_TMC_PASSWORD", password, sizeof(password));
  int got_session_id =
      copy_env("HTTP_X_TMC_SESSION_ID", session_id, sizeof(session_id));
  if (!got_password && !got_session_id) {
    fprintf(stderr, "Request provided no password and no session ID.\n");
    return respond(400, "Bad Request");
  }
  if (!do_auth(username, password, session_id)) {
    return respond(403, "Forbidden");
  }
  if (!make_datadir()) {
    return respond(500, "Internal Server Error");
  }
  if (!save_incoming_data(username, content_length)) {
    fprintf(stderr, "Data transfer failed.\n");
    return respond(500, "Internal Server Error");
  }
  return respond(200, "OK");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <init_settings_from_env@plt>
cmp    $0x0,%eax
jne    1217 <main+0x57>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1f4,%edi
lea    0xe23(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <do_special_invocation@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1249 <main+0x89>
mov    $0xc8,%edi
lea    0xe07(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
cmpl   $0x0,-0x14(%rbp)
jne    126c <main+0xac>
mov    $0x1f4,%edi
lea    0xdce(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
jmp    1271 <main+0xb1>
mov    $0x0,%al
call   10b0 <is_method_post@plt>
cmp    $0x0,%eax
jne    12af <main+0xef>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x195,%edi
lea    0xdb9(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
mov    $0x0,%al
call   10e0 <get_content_length@plt>
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x10,%edx
call   1070 <copy_env@plt>
cmp    $0x0,%eax
jne    1305 <main+0x145>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xdb0(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x30(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     134d <main+0x18d>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xd68(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x130(%rbp),%rsi
lea    0xd76(%rip),%rdi
mov    $0x100,%edx
call   1070 <copy_env@plt>
cmp    $0x0,%eax
jne    139c <main+0x1dc>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xd19(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
movsbl -0x130(%rbp),%eax
cmp    $0x2e,%eax
jne    13da <main+0x21a>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xcdb(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x130(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1423 <main+0x263>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xc92(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x230(%rbp),%rsi
lea    0xd08(%rip),%rdi
mov    $0x100,%edx
call   1070 <copy_env@plt>
mov    %eax,-0x334(%rbp)
lea    -0x330(%rbp),%rsi
lea    0xcfe(%rip),%rdi
mov    $0x100,%edx
call   1070 <copy_env@plt>
mov    %eax,-0x338(%rbp)
cmpl   $0x0,-0x334(%rbp)
jne    14a7 <main+0x2e7>
cmpl   $0x0,-0x338(%rbp)
jne    14a7 <main+0x2e7>
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x190,%edi
lea    0xc0e(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x130(%rbp),%rdi
lea    -0x230(%rbp),%rsi
lea    -0x330(%rbp),%rdx
call   1050 <do_auth@plt>
cmp    $0x0,%eax
jne    14e3 <main+0x323>
mov    $0x193,%edi
lea    0xcbe(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
mov    $0x0,%al
call   10d0 <make_datadir@plt>
cmp    $0x0,%eax
jne    150c <main+0x34c>
mov    $0x1f4,%edi
lea    0xb2e(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <save_incoming_data@plt>
cmp    $0x0,%eax
jne    1552 <main+0x392>
mov    0x2ab5(%rip),%rax
mov    (%rax),%edi
lea    0xc6a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1f4,%edi
lea    0xae8(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
jmp    1566 <main+0x3a6>
mov    $0xc8,%edi
lea    0xae5(%rip),%rsi
call   1030 <respond@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x318,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10c0 <init_settings_from_env@plt>
test   %eax,%eax
je     11fa <main+0x3a>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <do_special_invocation@plt>
test   %eax,%eax
je     120f <main+0x4f>
cmp    $0x1,%eax
jne    1229 <main+0x69>
lea    0xe50(%rip),%rsi
mov    $0xc8,%edi
jmp    121b <main+0x5b>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xe17(%rip),%rsi
mov    $0x1f4,%edi
add    $0x318,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <respond@plt>
xor    %eax,%eax
call   10b0 <is_method_post@plt>
test   %eax,%eax
je     127b <main+0xbb>
xor    %eax,%eax
call   10e0 <get_content_length@plt>
mov    %eax,%ebx
lea    0xe2a(%rip),%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1070 <copy_env@plt>
test   %eax,%eax
je     12a1 <main+0xe1>
lea    0xe58(%rip),%rsi
mov    %rsp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12d1 <main+0x111>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
jmp    12b1 <main+0xf1>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xdc4(%rip),%rsi
mov    $0x195,%edi
jmp    121b <main+0x5b>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xdeb(%rip),%rsi
mov    $0x190,%edi
call   1030 <respond@plt>
add    $0x318,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1070 <copy_env@plt>
test   %eax,%eax
je     1304 <main+0x144>
cmpb   $0x2e,0x10(%rsp)
jne    1316 <main+0x156>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
jmp    12b1 <main+0xf1>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
jmp    12b1 <main+0xf1>
lea    0x10(%rsp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     133f <main+0x17f>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
jmp    12b1 <main+0xf1>
lea    0xdf3(%rip),%rdi
lea    0x210(%rsp),%rsi
mov    $0x100,%edx
call   1070 <copy_env@plt>
mov    %eax,%ebp
lea    0xdec(%rip),%rdi
lea    0x110(%rsp),%rsi
mov    $0x100,%edx
call   1070 <copy_env@plt>
or     %ebp,%eax
je     13c1 <main+0x201>
lea    0x10(%rsp),%rdi
lea    0x210(%rsp),%rsi
lea    0x110(%rsp),%rdx
call   1050 <do_auth@plt>
test   %eax,%eax
je     13d6 <main+0x216>
xor    %eax,%eax
call   10d0 <make_datadir@plt>
test   %eax,%eax
je     13fc <main+0x23c>
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1040 <save_incoming_data@plt>
test   %eax,%eax
je     13e7 <main+0x227>
lea    0xc8c(%rip),%rsi
mov    $0xc8,%edi
jmp    12c2 <main+0x102>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
jmp    12b1 <main+0xf1>
lea    0xdb7(%rip),%rsi
mov    $0x193,%edi
jmp    12c2 <main+0x102>
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xc2a(%rip),%rsi
mov    $0x1f4,%edi
jmp    12c2 <main+0x102>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Exiting due to missing or invalid settings.\0A\00"
@.str.1 = [22 x i8] c"Internal Server Error\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [21 x i8] c"Not a POST request.\0A\00"
@.str.4 = [19 x i8] c"Method Not Allowed\00"
@.str.5 = [19 x i8] c"HTTP_X_TMC_VERSION\00"
@.str.6 = [39 x i8] c"Protocol version missing or too long.\0A\00"
@.str.7 = [12 x i8] c"Bad Request\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [27 x i8] c"Unknown protocol version.\0A\00"
@.str.10 = [20 x i8] c"HTTP_X_TMC_USERNAME\00"
@.str.11 = [31 x i8] c"Username missing or too long.\0A\00"
@.str.12 = [27 x i8] c"Username starts with '.'.\0A\00"
@.str.13 = [26 x i8] c"Username contains a '/'.\0A\00"
@.str.14 = [20 x i8] c"HTTP_X_TMC_PASSWORD\00"
@.str.15 = [22 x i8] c"HTTP_X_TMC_SESSION_ID\00"
@.str.16 = [49 x i8] c"Request provided no password and no session ID.\0A\00"
@.str.17 = [10 x i8] c"Forbidden\00"
@.str.18 = [23 x i8] c"Data transfer failed.\0A\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 [16 x i8]
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @init_settings_from_env()
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %3
br label %121
20: ; preds = %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @do_special_invocation(i32 %21, i8** %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @respond(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %27, i32* %3
br label %121
28: ; preds = %20
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 %32, i32* %3
br label %121
33: ; preds = %28
br label %34
34: ; preds = %33
%35 = call i32 (...) @is_method_post()
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @respond(i32 405, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 %40, i32* %3
br label %121
41: ; preds = %34
%42 = call i32 (...) @get_content_length()
store i32 %42, i32* %7
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%44 = call i32 @copy_env(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %43, i32 16)
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %49, i32* %3
br label %121
50: ; preds = %41
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%57 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %57, i32* %3
br label %121
58: ; preds = %50
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%60 = call i32 @copy_env(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i8* %59, i32 256)
%61 = icmp ne i32 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%65 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %65, i32* %3
br label %121
66: ; preds = %58
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 46
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
%74 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %74, i32* %3
br label %121
75: ; preds = %66
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%77 = call i64 @strchr(i8* %76, i8 signext 47)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0))
%82 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %82, i32* %3
br label %121
83: ; preds = %75
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%85 = call i32 @copy_env(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %84, i32 256)
store i32 %85, i32* %12
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%87 = call i32 @copy_env(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i8* %86, i32 256)
store i32 %87, i32* %13
%88 = load i32, i32* %12
%89 = icmp ne i32 %88, 0
br i1 %89, label %97, label %90
90: ; preds = %83
%91 = load i32, i32* %13
%92 = icmp ne i32 %91, 0
br i1 %92, label %97, label %93
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.16, i64 0, i64 0))
%96 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 %96, i32* %3
br label %121
97: ; preds = %90, %83
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%101 = call i32 @do_auth(i8* %98, i8* %99, i8* %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %105, label %103
103: ; preds = %97
%104 = call i32 @respond(i32 403, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i64 0, i64 0))
store i32 %104, i32* %3
br label %121
105: ; preds = %97
%106 = call i32 (...) @make_datadir()
%107 = icmp ne i32 %106, 0
br i1 %107, label %110, label %108
108: ; preds = %105
%109 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 %109, i32* %3
br label %121
110: ; preds = %105
%111 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%112 = load i32, i32* %7
%113 = call i32 @save_incoming_data(i8* %111, i32 %112)
%114 = icmp ne i32 %113, 0
br i1 %114, label %119, label %115
115: ; preds = %110
%116 = load i32, i32* @stderr
%117 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.18, i64 0, i64 0))
%118 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 %118, i32* %3
br label %121
119: ; preds = %110
%120 = call i32 @respond(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %120, i32* %3
br label %121
121: ; preds = %119, %115, %108, %103, %93, %79, %71, %62, %54, %46, %37, %31, %26, %16
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Exiting due to missing or invalid settings.\0A\00"
@.str.1 = [22 x i8] c"Internal Server Error\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [21 x i8] c"Not a POST request.\0A\00"
@.str.4 = [19 x i8] c"Method Not Allowed\00"
@.str.5 = [19 x i8] c"HTTP_X_TMC_VERSION\00"
@.str.6 = [39 x i8] c"Protocol version missing or too long.\0A\00"
@.str.7 = [12 x i8] c"Bad Request\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [27 x i8] c"Unknown protocol version.\0A\00"
@.str.10 = [20 x i8] c"HTTP_X_TMC_USERNAME\00"
@.str.11 = [31 x i8] c"Username missing or too long.\0A\00"
@.str.12 = [27 x i8] c"Username starts with '.'.\0A\00"
@.str.13 = [26 x i8] c"Username contains a '/'.\0A\00"
@.str.14 = [20 x i8] c"HTTP_X_TMC_PASSWORD\00"
@.str.15 = [22 x i8] c"HTTP_X_TMC_SESSION_ID\00"
@.str.16 = [49 x i8] c"Request provided no password and no session ID.\0A\00"
@.str.17 = [10 x i8] c"Forbidden\00"
@.str.18 = [23 x i8] c"Data transfer failed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [16 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = tail call i32 (...) @init_settings_from_env()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %101
13: ; preds = %2
%14 = tail call i32 @do_special_invocation(i32 %0, i8** %1)
switch i32 %14, label %19 [
i32 1, label %15
i32 0, label %17
]
15: ; preds = %13
%16 = tail call i32 @respond(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %101
17: ; preds = %13
%18 = tail call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %101
19: ; preds = %13
%20 = tail call i32 (...) @is_method_post()
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @respond(i32 405, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %101
26: ; preds = %19
%27 = tail call i32 (...) @get_content_length()
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%29 = call i32 @copy_env(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %28, i32 16)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %99
35: ; preds = %26
%36 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%41 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %99
42: ; preds = %35
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%44 = call i32 @copy_env(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i8* %43, i32 256)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%49 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %97
50: ; preds = %42
%51 = load i8, i8* %43
%52 = icmp eq i8 %51, 46
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
%56 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %97
57: ; preds = %50
%58 = call i64 @strchr(i8* %43, i8 signext 47)
%59 = icmp eq i64 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0))
%63 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %97
64: ; preds = %57
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%67 = call i32 @copy_env(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %65, i32 256)
%68 = call i32 @copy_env(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i8* %66, i32 256)
%69 = icmp ne i32 %67, 0
%70 = icmp ne i32 %68, 0
%71 = select i1 %69, i1 true, i1 %70
br i1 %71, label %76, label %72
72: ; preds = %64
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.16, i64 0, i64 0))
%75 = call i32 @respond(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %95
76: ; preds = %64
%77 = call i32 @do_auth(i8* %43, i8* %65, i8* %66)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @respond(i32 403, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i64 0, i64 0))
br label %95
81: ; preds = %76
%82 = call i32 (...) @make_datadir()
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %95
86: ; preds = %81
%87 = call i32 @save_incoming_data(i8* %43, i32 %27)
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.18, i64 0, i64 0))
%92 = call i32 @respond(i32 500, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %95
93: ; preds = %86
%94 = call i32 @respond(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %95
95: ; preds = %93, %89, %84, %79, %72
%96 = phi i32 [ %94, %93 ], [ %92, %89 ], [ %85, %84 ], [ %80, %79 ], [ %75, %72 ]
br label %97
97: ; preds = %95, %60, %53, %46
%98 = phi i32 [ %56, %53 ], [ %63, %60 ], [ %96, %95 ], [ %49, %46 ]
br label %99
99: ; preds = %97, %38, %31
%100 = phi i32 [ %41, %38 ], [ %98, %97 ], [ %34, %31 ]
br label %101
101: ; preds = %15, %17, %22, %99, %9
%102 = phi i32 [ %12, %9 ], [ %16, %15 ], [ %18, %17 ], [ %100, %99 ], [ %25, %22 ]
ret i32 %102
}