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

/* Variables and functions */
int SHA1_Final(unsigned char *, int /*<<< orphan*/ *);
int SHA1_Init(int /*<<< orphan*/ *);
int SHA1_Update(int /*<<< orphan*/ *, char const *, int);
int SHA_DIGEST_LENGTH;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *getenv(char *);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
scalar_t__ parse_query_param(char **, char **, char **);
int /*<<< orphan*/ split_fields(char *, char **, char **, char **, char **,
                                char **);
int sscanf(char *, char *, unsigned char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char const *);
int url_decode(char *);
int main(int argc, char **argv) {
  const char *secret;
  secret = getenv("TRACKING_SECRET");
  if (!secret) {
    fprintf(stderr, "TRACKING_SECRET not set\n");
    return 1;
  }
  char input_line[2048];
  unsigned char input_hash[SHA_DIGEST_LENGTH];
  unsigned char expected_hash[SHA_DIGEST_LENGTH];
  int secret_length = strlen(secret);
  while (fgets(input_line, 2048, stdin) != NULL) {
    char *ip, *path, *query, *unique_id;
    split_fields(input_line, &ip, &path, &query, &unique_id, ((char **)NULL));
    char *id = NULL;
    char *hash = NULL;
    char *key, *value;
    while (parse_query_param(&query, &key, &value) >= 0) {
      if (strcmp(key, "id") == 0) {
        id = value;
      } else if (strcmp(key, "hash") == 0) {
        hash = value;
      }
    }
    if (id == NULL || hash == NULL)
      continue;
    int id_length = url_decode(id);
    if (id_length < 0)
      continue;
    if (url_decode(hash) != 40)
      continue;
    bool bad_hash = false;
    for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
      int count = sscanf(&hash[i * 2], "%2hhx", &input_hash[i]);
      if (count != 1) {
        bad_hash = true;
        break;
      }
    }
    if (bad_hash)
      continue;
    SHA_CTX ctx;
    int result = 0;
    result = SHA1_Init(&ctx);
    if (result == 0)
      continue;
    if (strcmp("/pixel/of_defenestration.png", path) != 0) {
      result = SHA1_Update(&ctx, ip, strlen(ip));
      if (result == 0)
        continue;
    }
    result = SHA1_Update(&ctx, id, id_length);
    if (result == 0)
      continue;
    result = SHA1_Update(&ctx, secret, secret_length);
    if (result == 0)
      continue;
    result = SHA1_Final(expected_hash, &ctx);
    if (result == 0)
      continue;
    if (memcmp(input_hash, expected_hash, SHA_DIGEST_LENGTH) != 0)
      continue;
    char *fullname = id;
    char *subreddit = NULL;
    for (char *c = id; *c != '\0'; c++) {
      if (*c == '-') {
        subreddit = c + 1;
        *c = '\0';
        break;
      }
    }
    fputs(unique_id, stdout);
    fputc('\t', stdout);
    fputs(path, stdout);
    fputc('\t', stdout);
    fputs(fullname, stdout);
    fputc('\t', stdout);
    if (subreddit != NULL) {
      fputs(subreddit, stdout);
    }
    fputc('\n', stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <main+0x55>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1737 <main+0x547>
mov    0x2d94(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x828(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x8c0(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x830(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x8b8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x838(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x83c(%rbp)
lea    -0x820(%rbp),%rdi
mov    0x2d2d(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     172d <main+0x53d>
lea    -0x820(%rbp),%rdi
lea    -0x848(%rbp),%rsi
lea    -0x850(%rbp),%rdx
lea    -0x858(%rbp),%rcx
lea    -0x860(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   10f0 <split_fields@plt>
movq   $0x0,-0x868(%rbp)
movq   $0x0,-0x870(%rbp)
lea    -0x858(%rbp),%rdi
lea    -0x878(%rbp),%rsi
lea    -0x880(%rbp),%rdx
call   10c0 <parse_query_param@plt>
cmp    $0x0,%rax
jl     139d <main+0x1ad>
mov    -0x878(%rbp),%rdi
lea    0xce3(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1368 <main+0x178>
mov    -0x880(%rbp),%rax
mov    %rax,-0x868(%rbp)
jmp    1398 <main+0x1a8>
mov    -0x878(%rbp),%rdi
lea    0xcb6(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1393 <main+0x1a3>
mov    -0x880(%rbp),%rax
mov    %rax,-0x870(%rbp)
jmp    1398 <main+0x1a8>
jmp    1314 <main+0x124>
cmpq   $0x0,-0x868(%rbp)
je     13b9 <main+0x1c9>
cmpq   $0x0,-0x870(%rbp)
jne    13be <main+0x1ce>
jmp    12ad <main+0xbd>
mov    -0x868(%rbp),%rdi
call   1060 <url_decode@plt>
mov    %eax,-0x884(%rbp)
cmpl   $0x0,-0x884(%rbp)
jge    13e2 <main+0x1f2>
jmp    12ad <main+0xbd>
mov    -0x870(%rbp),%rdi
call   1060 <url_decode@plt>
cmp    $0x28,%eax
je     13fc <main+0x20c>
jmp    12ad <main+0xbd>
movl   $0x0,-0x888(%rbp)
movl   $0x0,-0x88c(%rbp)
mov    -0x88c(%rbp),%eax
mov    0x2bc3(%rip),%rcx
cmp    (%rcx),%eax
jge    1492 <main+0x2a2>
mov    -0x8c0(%rbp),%rdx
mov    -0x870(%rbp),%rdi
mov    -0x88c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x88c(%rbp),%rax
add    %rax,%rdx
lea    0xbdf(%rip),%rsi
call   10e0 <sscanf@plt>
mov    %eax,-0x890(%rbp)
cmpl   $0x1,-0x890(%rbp)
je     1479 <main+0x289>
movl   $0x1,-0x888(%rbp)
jmp    1492 <main+0x2a2>
jmp    147e <main+0x28e>
mov    -0x88c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88c(%rbp)
jmp    1410 <main+0x220>
cmpl   $0x0,-0x888(%rbp)
je     14a4 <main+0x2b4>
jmp    12ad <main+0xbd>
movl   $0x0,-0x898(%rbp)
lea    -0x894(%rbp),%rdi
call   1100 <SHA1_Init@plt>
mov    %eax,-0x898(%rbp)
cmpl   $0x0,-0x898(%rbp)
jne    14d2 <main+0x2e2>
jmp    12ad <main+0xbd>
mov    -0x850(%rbp),%rsi
lea    0xb57(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     153b <main+0x34b>
mov    -0x848(%rbp),%rax
mov    %rax,-0x8c8(%rbp)
mov    -0x848(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c8(%rbp),%rsi
mov    %eax,%edx
lea    -0x894(%rbp),%rdi
call   10d0 <SHA1_Update@plt>
mov    %eax,-0x898(%rbp)
cmpl   $0x0,-0x898(%rbp)
jne    1536 <main+0x346>
jmp    12ad <main+0xbd>
jmp    153b <main+0x34b>
mov    -0x868(%rbp),%rsi
mov    -0x884(%rbp),%edx
lea    -0x894(%rbp),%rdi
call   10d0 <SHA1_Update@plt>
mov    %eax,-0x898(%rbp)
cmpl   $0x0,-0x898(%rbp)
jne    156c <main+0x37c>
jmp    12ad <main+0xbd>
mov    -0x18(%rbp),%rsi
mov    -0x83c(%rbp),%edx
lea    -0x894(%rbp),%rdi
call   10d0 <SHA1_Update@plt>
mov    %eax,-0x898(%rbp)
cmpl   $0x0,-0x898(%rbp)
jne    159a <main+0x3aa>
jmp    12ad <main+0xbd>
mov    -0x8b8(%rbp),%rdi
lea    -0x894(%rbp),%rsi
call   1110 <SHA1_Final@plt>
mov    %eax,-0x898(%rbp)
cmpl   $0x0,-0x898(%rbp)
jne    15c5 <main+0x3d5>
jmp    12ad <main+0xbd>
mov    -0x8b8(%rbp),%rsi
mov    -0x8c0(%rbp),%rdi
mov    0x2a06(%rip),%rax
mov    (%rax),%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     15f0 <main+0x400>
jmp    12ad <main+0xbd>
mov    -0x868(%rbp),%rax
mov    %rax,-0x8a0(%rbp)
movq   $0x0,-0x8a8(%rbp)
mov    -0x868(%rbp),%rax
mov    %rax,-0x8b0(%rbp)
mov    -0x8b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     167a <main+0x48a>
mov    -0x8b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    165e <main+0x46e>
mov    -0x8b0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8a8(%rbp)
mov    -0x8b0(%rbp),%rax
movb   $0x0,(%rax)
jmp    167a <main+0x48a>
jmp    1663 <main+0x473>
mov    -0x8b0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8b0(%rbp)
jmp    1617 <main+0x427>
mov    -0x860(%rbp),%rdi
mov    0x2940(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2932(%rip),%rax
mov    (%rax),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
mov    -0x850(%rbp),%rdi
mov    0x2918(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x290a(%rip),%rax
mov    (%rax),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
mov    -0x8a0(%rbp),%rdi
mov    0x28f0(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x28e2(%rip),%rax
mov    (%rax),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
cmpq   $0x0,-0x8a8(%rbp)
je     1715 <main+0x525>
mov    -0x8a8(%rbp),%rdi
mov    0x28ba(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x28ac(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1070 <fputc@plt>
jmp    12ad <main+0xbd>
mov    -0x828(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x868,%rsp
lea    0xdf5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1294 <main+0xa4>
mov    %rsp,-0x68(%rbp)
mov    0x2dc0(%rip),%rdx
mov    (%rdx),%ecx
mov    %rsp,%rsi
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rsi
mov    %rsi,-0x50(%rbp)
mov    %rsi,%rsp
mov    (%rdx),%ecx
mov    %rsp,%rdx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x60(%rbp)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
lea    -0x890(%rbp),%rdi
mov    $0x800,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     1540 <main+0x350>
lea    -0x890(%rbp),%rbx
lea    -0x88(%rbp),%r15
lea    -0x30(%rbp),%r14
jmp    12ea <main+0xfa>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%eax
jmp    1546 <main+0x356>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1070 <fputc@plt>
nop
mov    0x2d21(%rip),%rax
mov    (%rax),%edx
lea    -0x890(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1090 <fgets@plt>
test   %rax,%rax
lea    -0x30(%rbp),%r14
je     1540 <main+0x350>
mov    %rbx,%rdi
lea    -0x78(%rbp),%rsi
lea    -0x58(%rbp),%rdx
mov    %r15,%rcx
lea    -0x70(%rbp),%r8
xor    %r9d,%r9d
call   10f0 <split_fields@plt>
mov    %r15,%rdi
mov    %r14,%rsi
lea    -0x38(%rbp),%rdx
call   10c0 <parse_query_param@plt>
test   %rax,%rax
js     12c0 <main+0xd0>
xor    %r12d,%r12d
xor    %r13d,%r13d
lea    -0x30(%rbp),%rbx
lea    -0x38(%rbp),%r14
jmp    1347 <main+0x157>
nopl   0x0(%rax,%rax,1)
mov    -0x38(%rbp),%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <parse_query_param@plt>
test   %rax,%rax
js     1380 <main+0x190>
mov    -0x30(%rbp),%rdi
lea    0xcd7(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1330 <main+0x140>
mov    -0x30(%rbp),%rdi
lea    0xcc5(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1334 <main+0x144>
mov    -0x38(%rbp),%r13
jmp    1334 <main+0x144>
nopw   0x0(%rax,%rax,1)
test   %r12,%r12
je     12c0 <main+0xd0>
test   %r13,%r13
je     12c0 <main+0xd0>
mov    %r12,%rdi
call   1060 <url_decode@plt>
test   %eax,%eax
js     12c0 <main+0xd0>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <url_decode@plt>
cmp    $0x28,%eax
jne    12c0 <main+0xd0>
mov    0x2c24(%rip),%rax
cmpl   $0x0,(%rax)
jle    1407 <main+0x217>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x50(%rbp),%rax
lea    (%rax,%r14,1),%rdx
mov    %r13,%rdi
lea    0xc4f(%rip),%rsi
call   10e0 <sscanf@plt>
cmp    $0x1,%eax
jne    12c0 <main+0xd0>
add    $0x1,%r14
mov    0x2be5(%rip),%rax
movslq (%rax),%rax
add    $0x2,%r13
cmp    %rax,%r14
jl     13d0 <main+0x1e0>
mov    %ebx,%r14d
lea    -0x7c(%rbp),%rbx
mov    %rbx,%rdi
call   1100 <SHA1_Init@plt>
test   %eax,%eax
je     12c0 <main+0xd0>
mov    -0x58(%rbp),%rsi
lea    0xc0e(%rip),%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1454 <main+0x264>
mov    -0x78(%rbp),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   10d0 <SHA1_Update@plt>
test   %eax,%eax
je     12c0 <main+0xd0>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   10d0 <SHA1_Update@plt>
test   %eax,%eax
je     12c0 <main+0xd0>
mov    %rbx,%rdi
mov    -0x60(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   10d0 <SHA1_Update@plt>
test   %eax,%eax
je     12c0 <main+0xd0>
mov    -0x48(%rbp),%rdi
mov    %rbx,%rsi
call   1110 <SHA1_Final@plt>
test   %eax,%eax
je     12c0 <main+0xd0>
mov    0x2b44(%rip),%rax
mov    (%rax),%edx
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1080 <memcmp@plt>
test   %rax,%rax
jne    12c0 <main+0xd0>
lea    0x1(%r12),%r13
nopl   0x0(%rax)
movzbl -0x1(%r13),%eax
test   %al,%al
je     14d3 <main+0x2e3>
cmp    $0x2d,%al
je     14d8 <main+0x2e8>
add    $0x1,%r13
jmp    14c0 <main+0x2d0>
xor    %r13d,%r13d
jmp    14dd <main+0x2ed>
movb   $0x0,-0x1(%r13)
mov    -0x70(%rbp),%rdi
mov    0x2ae0(%rip),%rbx
mov    (%rbx),%esi
call   1050 <fputs@plt>
mov    (%rbx),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
mov    -0x58(%rbp),%rdi
mov    (%rbx),%esi
call   1050 <fputs@plt>
mov    (%rbx),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
mov    (%rbx),%esi
mov    %r12,%rdi
call   1050 <fputs@plt>
mov    (%rbx),%esi
mov    $0x9,%edi
call   1070 <fputc@plt>
test   %r13,%r13
je     12b3 <main+0xc3>
mov    (%rbx),%esi
mov    %r13,%rdi
call   1050 <fputs@plt>
jmp    12b3 <main+0xc3>
mov    -0x68(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"TRACKING_SECRET\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"TRACKING_SECRET not set\0A\00"
@SHA_DIGEST_LENGTH = global i32 0
@stdin = global i32 0
@.str.2 = [3 x i8] c"id\00"
@.str.3 = [5 x i8] c"hash\00"
@.str.4 = [6 x i8] c"%2hhx\00"
@.str.5 = [29 x i8] c"/pixel/of_defenestration.png\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [2048 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i8*
%27 = alloca i8*
%28 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %2
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %204
35: ; preds = %2
%36 = load i32, i32* @SHA_DIGEST_LENGTH
%37 = zext i32 %36 to i64
%38 = call i8* @llvm.stacksave()
store i8* %38, i8** %8
%39 = alloca i8, i64 %37
store i64 %37, i64* %9
%40 = load i32, i32* @SHA_DIGEST_LENGTH
%41 = zext i32 %40 to i64
%42 = alloca i8, i64 %41
store i64 %41, i64* %10
%43 = load i8*, i8** %6
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %11
br label %45
45: ; preds = %199, %155, %150, %145, %138, %130, %118, %113, %87, %82, %76, %35
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32* @fgets(i8* %46, i32 2048, i32 %47)
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %202
50: ; preds = %45
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%52 = call i32 @split_fields(i8* %51, i8** %12, i8** %13, i8** %14, i8** %15, i8** null)
store i8* null, i8** %16
store i8* null, i8** %17
br label %53
53: ; preds = %69, %50
%54 = call i64 @parse_query_param(i8** %14, i8** %18, i8** %19)
%55 = icmp sge i64 %54, 0
br i1 %55, label %56, label %70
56: ; preds = %53
%57 = load i8*, i8** %18
%58 = call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load i8*, i8** %19
store i8* %61, i8** %16
br label %69
62: ; preds = %56
%63 = load i8*, i8** %18
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = load i8*, i8** %19
store i8* %67, i8** %17
br label %68
68: ; preds = %66, %62
br label %69
69: ; preds = %68, %60
br label %53
70: ; preds = %53
%71 = load i8*, i8** %16
%72 = icmp eq i8* %71, null
br i1 %72, label %76, label %73
73: ; preds = %70
%74 = load i8*, i8** %17
%75 = icmp eq i8* %74, null
br i1 %75, label %76, label %77
76: ; preds = %73, %70
br label %45
77: ; preds = %73
%78 = load i8*, i8** %16
%79 = call i32 @url_decode(i8* %78)
store i32 %79, i32* %20
%80 = load i32, i32* %20
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %77
br label %45
83: ; preds = %77
%84 = load i8*, i8** %17
%85 = call i32 @url_decode(i8* %84)
%86 = icmp ne i32 %85, 40
br i1 %86, label %87, label %88
87: ; preds = %83
br label %45
88: ; preds = %83
store i32 0, i32* %21
store i32 0, i32* %22
br label %89
89: ; preds = %107, %88
%90 = load i32, i32* %22
%91 = load i32, i32* @SHA_DIGEST_LENGTH
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %110
93: ; preds = %89
%94 = load i8*, i8** %17
%95 = load i32, i32* %22
%96 = mul nsw i32 %95, 2
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %94, i64 %97
%99 = load i32, i32* %22
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %39, i64 %100
%102 = call i32 @sscanf(i8* %98, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %101)
store i32 %102, i32* %23
%103 = load i32, i32* %23
%104 = icmp ne i32 %103, 1
br i1 %104, label %105, label %106
105: ; preds = %93
store i32 1, i32* %21
br label %110
106: ; preds = %93
br label %107
107: ; preds = %106
%108 = load i32, i32* %22
%109 = add nsw i32 %108, 1
store i32 %109, i32* %22
br label %89
110: ; preds = %105, %89
%111 = load i32, i32* %21
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %114
113: ; preds = %110
br label %45
114: ; preds = %110
store i32 0, i32* %25
%115 = call i32 @SHA1_Init(i32* %24)
store i32 %115, i32* %25
%116 = load i32, i32* %25
%117 = icmp eq i32 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %114
br label %45
119: ; preds = %114
%120 = load i8*, i8** %13
%121 = call i64 @strcmp(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %120)
%122 = icmp ne i64 %121, 0
br i1 %122, label %123, label %132
123: ; preds = %119
%124 = load i8*, i8** %12
%125 = load i8*, i8** %12
%126 = call i32 @strlen(i8* %125)
%127 = call i32 @SHA1_Update(i32* %24, i8* %124, i32 %126)
store i32 %127, i32* %25
%128 = load i32, i32* %25
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %131
130: ; preds = %123
br label %45
131: ; preds = %123
br label %132
132: ; preds = %131, %119
%133 = load i8*, i8** %16
%134 = load i32, i32* %20
%135 = call i32 @SHA1_Update(i32* %24, i8* %133, i32 %134)
store i32 %135, i32* %25
%136 = load i32, i32* %25
%137 = icmp eq i32 %136, 0
br i1 %137, label %138, label %139
138: ; preds = %132
br label %45
139: ; preds = %132
%140 = load i8*, i8** %6
%141 = load i32, i32* %11
%142 = call i32 @SHA1_Update(i32* %24, i8* %140, i32 %141)
store i32 %142, i32* %25
%143 = load i32, i32* %25
%144 = icmp eq i32 %143, 0
br i1 %144, label %145, label %146
145: ; preds = %139
br label %45
146: ; preds = %139
%147 = call i32 @SHA1_Final(i8* %42, i32* %24)
store i32 %147, i32* %25
%148 = load i32, i32* %25
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %151
150: ; preds = %146
br label %45
151: ; preds = %146
%152 = load i32, i32* @SHA_DIGEST_LENGTH
%153 = call i64 @memcmp(i8* %39, i8* %42, i32 %152)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %156
155: ; preds = %151
br label %45
156: ; preds = %151
%157 = load i8*, i8** %16
store i8* %157, i8** %26
store i8* null, i8** %27
%158 = load i8*, i8** %16
store i8* %158, i8** %28
br label %159
159: ; preds = %174, %156
%160 = load i8*, i8** %28
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = icmp ne i32 %162, 0
br i1 %163, label %164, label %177
164: ; preds = %159
%165 = load i8*, i8** %28
%166 = load i8, i8* %165
%167 = sext i8 %166 to i32
%168 = icmp eq i32 %167, 45
br i1 %168, label %169, label %173
169: ; preds = %164
%170 = load i8*, i8** %28
%171 = getelementptr inbounds i8, i8* %170, i64 1
store i8* %171, i8** %27
%172 = load i8*, i8** %28
store i8 0, i8* %172
br label %177
173: ; preds = %164
br label %174
174: ; preds = %173
%175 = load i8*, i8** %28
%176 = getelementptr inbounds i8, i8* %175, i32 1
store i8* %176, i8** %28
br label %159
177: ; preds = %169, %159
%178 = load i8*, i8** %15
%179 = load i32, i32* @stdout
%180 = call i32 @fputs(i8* %178, i32 %179)
%181 = load i32, i32* @stdout
%182 = call i32 @fputc(i8 signext 9, i32 %181)
%183 = load i8*, i8** %13
%184 = load i32, i32* @stdout
%185 = call i32 @fputs(i8* %183, i32 %184)
%186 = load i32, i32* @stdout
%187 = call i32 @fputc(i8 signext 9, i32 %186)
%188 = load i8*, i8** %26
%189 = load i32, i32* @stdout
%190 = call i32 @fputs(i8* %188, i32 %189)
%191 = load i32, i32* @stdout
%192 = call i32 @fputc(i8 signext 9, i32 %191)
%193 = load i8*, i8** %27
%194 = icmp ne i8* %193, null
br i1 %194, label %195, label %199
195: ; preds = %177
%196 = load i8*, i8** %27
%197 = load i32, i32* @stdout
%198 = call i32 @fputs(i8* %196, i32 %197)
br label %199
199: ; preds = %195, %177
%200 = load i32, i32* @stdout
%201 = call i32 @fputc(i8 signext 10, i32 %200)
br label %45
202: ; preds = %45
%203 = load i8*, i8** %8
br label %204
204: ; preds = %202, %32
%205 = load i32, i32* %3
ret i32 %205
}

LLVM IR (-O2):
@.str = [16 x i8] c"TRACKING_SECRET\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"TRACKING_SECRET not set\0A\00"
@SHA_DIGEST_LENGTH = global i32 0
@stdin = global i32 0
@.str.2 = [3 x i8] c"id\00"
@.str.3 = [5 x i8] c"hash\00"
@.str.4 = [6 x i8] c"%2hhx\00"
@.str.5 = [29 x i8] c"/pixel/of_defenestration.png\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %146
16: ; preds = %2
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* @SHA_DIGEST_LENGTH
%19 = zext i32 %18 to i64
%20 = tail call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = load i32, i32* @SHA_DIGEST_LENGTH
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
%25 = tail call i32 @strlen(i8* %11)
%26 = load i32, i32* @stdin
%27 = call i32* @fgets(i8* %17, i32 2048, i32 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %145, label %29
29: ; preds = %16
%30 = bitcast i8** %4 to i8*
%31 = bitcast i8** %5 to i8*
%32 = bitcast i8** %6 to i8*
%33 = bitcast i8** %7 to i8*
%34 = bitcast i8** %8 to i8*
%35 = bitcast i8** %9 to i8*
%36 = bitcast i32* %10 to i8*
br label %37
37: ; preds = %29, %141
%38 = call i32 @split_fields(i8* %17, i8** %4, i8** %5, i8** %6, i8** %7, i8** null)
%39 = call i64 @parse_query_param(i8** %6, i8** %8, i8** %9)
%40 = icmp sgt i64 %39, -1
br i1 %40, label %41, label %141
41: ; preds = %37, %55
%42 = phi i8* [ %57, %55 ], [ null, %37 ]
%43 = phi i8* [ %56, %55 ], [ null, %37 ]
%44 = load i8*, i8** %8
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = load i8*, i8** %9
br label %55
49: ; preds = %41
%50 = load i8*, i8** %8
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
%53 = load i8*, i8** %9
%54 = select i1 %52, i8* %53, i8* %43
br label %55
55: ; preds = %49, %47
%56 = phi i8* [ %43, %47 ], [ %54, %49 ]
%57 = phi i8* [ %48, %47 ], [ %42, %49 ]
%58 = call i64 @parse_query_param(i8** %6, i8** %8, i8** %9)
%59 = icmp sgt i64 %58, -1
br i1 %59, label %41, label %60
60: ; preds = %55
%61 = icmp eq i8* %57, null
%62 = icmp eq i8* %56, null
%63 = select i1 %61, i1 true, i1 %62
br i1 %63, label %141, label %64
64: ; preds = %60
%65 = call i32 @url_decode(i8* %57)
%66 = icmp slt i32 %65, 0
br i1 %66, label %141, label %67
67: ; preds = %64
%68 = call i32 @url_decode(i8* %56)
%69 = icmp eq i32 %68, 40
br i1 %69, label %70, label %141
70: ; preds = %67
%71 = load i32, i32* @SHA_DIGEST_LENGTH
%72 = icmp sgt i32 %71, 0
br i1 %72, label %77, label %85
73: ; preds = %77
%74 = load i32, i32* @SHA_DIGEST_LENGTH
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %84, %75
br i1 %76, label %77, label %85
77: ; preds = %70, %73
%78 = phi i64 [ %84, %73 ], [ 0, %70 ]
%79 = shl nuw nsw i64 %78, 1
%80 = getelementptr inbounds i8, i8* %56, i64 %79
%81 = getelementptr inbounds i8, i8* %21, i64 %78
%82 = call i32 @sscanf(i8* %80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = icmp eq i32 %82, 1
%84 = add nuw nsw i64 %78, 1
br i1 %83, label %73, label %141
85: ; preds = %73, %70
%86 = call i32 @SHA1_Init(i32* %10)
%87 = icmp eq i32 %86, 0
br i1 %87, label %140, label %88
88: ; preds = %85
%89 = load i8*, i8** %5
%90 = call i64 @strcmp(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %89)
%91 = icmp eq i64 %90, 0
br i1 %91, label %97, label %92
92: ; preds = %88
%93 = load i8*, i8** %4
%94 = call i32 @strlen(i8* %93)
%95 = call i32 @SHA1_Update(i32* %10, i8* %93, i32 %94)
%96 = icmp eq i32 %95, 0
br i1 %96, label %140, label %97
97: ; preds = %92, %88
%98 = call i32 @SHA1_Update(i32* %10, i8* %57, i32 %65)
%99 = icmp eq i32 %98, 0
br i1 %99, label %140, label %100
100: ; preds = %97
%101 = call i32 @SHA1_Update(i32* %10, i8* %11, i32 %25)
%102 = icmp eq i32 %101, 0
br i1 %102, label %140, label %103
103: ; preds = %100
%104 = call i32 @SHA1_Final(i8* %24, i32* %10)
%105 = icmp eq i32 %104, 0
br i1 %105, label %140, label %106
106: ; preds = %103
%107 = load i32, i32* @SHA_DIGEST_LENGTH
%108 = call i64 @memcmp(i8* %21, i8* %24, i32 %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %140
110: ; preds = %106, %115
%111 = phi i8* [ %116, %115 ], [ %57, %106 ]
%112 = load i8, i8* %111
switch i8 %112, label %115 [
i8 0, label %117
i8 45, label %113
]
113: ; preds = %110
%114 = getelementptr inbounds i8, i8* %111, i64 1
store i8 0, i8* %111
br label %117
115: ; preds = %110
%116 = getelementptr inbounds i8, i8* %111, i64 1
br label %110
117: ; preds = %110, %113
%118 = phi i8* [ %114, %113 ], [ null, %110 ]
%119 = load i8*, i8** %7
%120 = load i32, i32* @stdout
%121 = call i32 @fputs(i8* %119, i32 %120)
%122 = load i32, i32* @stdout
%123 = call i32 @fputc(i8 signext 9, i32 %122)
%124 = load i8*, i8** %5
%125 = load i32, i32* @stdout
%126 = call i32 @fputs(i8* %124, i32 %125)
%127 = load i32, i32* @stdout
%128 = call i32 @fputc(i8 signext 9, i32 %127)
%129 = load i32, i32* @stdout
%130 = call i32 @fputs(i8* %57, i32 %129)
%131 = load i32, i32* @stdout
%132 = call i32 @fputc(i8 signext 9, i32 %131)
%133 = icmp eq i8* %118, null
br i1 %133, label %137, label %134
134: ; preds = %117
%135 = load i32, i32* @stdout
%136 = call i32 @fputs(i8* %118, i32 %135)
br label %137
137: ; preds = %134, %117
%138 = load i32, i32* @stdout
%139 = call i32 @fputc(i8 signext 10, i32 %138)
br label %140
140: ; preds = %106, %103, %100, %97, %92, %85, %137
br label %141
141: ; preds = %77, %37, %64, %67, %140, %60
%142 = load i32, i32* @stdin
%143 = call i32* @fgets(i8* %17, i32 2048, i32 %142)
%144 = icmp eq i32* %143, null
br i1 %144, label %145, label %37
145: ; preds = %141, %16
br label %146
146: ; preds = %145, %13
%147 = phi i32 [ 0, %145 ], [ 1, %13 ]
ret i32 %147
}