#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 */
char *getenv(char *);
int /*<<< orphan*/ print_string_as_binary(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *, int *, int *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
size_t strspn(char *, char *);
int main(void) {
  int i;
  char *query_str = NULL;
  char *query_str_ptr = NULL;
  char query_str_emended[100];
  char input_hex_str[100];
  char hex_str[20];
  char *nh_hex_str = NULL;
  long long int _64hex = 0;
  int start_bit = 0;
  int end_bit = 0;
  int num_vars;
  int input_hex_str_len;
  printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1", 13, 10);
  printf("<TITLE>Decoded NH </TITLE>\n");
  query_str = getenv("QUERY_STRING");
  if (query_str == NULL) {
    printf("<P>Error! Error in passing query string (%p) to script.",
           query_str);
    return -1;
  }
  query_str += 8;
  if ((query_str[0] == '0') && (query_str[1] == 'x' || query_str[1] == 'X')) {
    query_str += 2;
  }
  i = 0;
  input_hex_str_len = 0;
  query_str_ptr = query_str;
  while (*query_str_ptr != '&') {
    input_hex_str_len++;
    query_str_ptr++;
    input_hex_str[i++] = *query_str_ptr;
  }
  input_hex_str[--i] = '\0';
  if (input_hex_str_len > 16) {
    printf("<P>Error! Input hex (0x%s) longer than 64 bit", input_hex_str);
    return -1;
  }
  if (input_hex_str[strspn(input_hex_str, "0123456789abcdefABCDEF")] != 0) {
    printf("<P>Error! Invalide input hex (0x%s)", input_hex_str);
    return -1;
  }
  query_str_emended[0] = '\0';
  for (i = 0; i < (16 - input_hex_str_len); i++) {
    strncat(query_str_emended, "0", (100 - strlen(query_str_emended) - 1));
  }
  strncat(query_str_emended, query_str, (100 - strlen(query_str_emended) - 1));
  num_vars = sscanf(query_str_emended, "%16s&start_bit=%d&end_bit=%d", hex_str,
                    &start_bit, &end_bit);
  if (num_vars != 3) {
    printf("<P>Error! 2Invalid query string (%s) to script.", query_str);
    return -1;
  }
  nh_hex_str = &hex_str[0];
  if ((start_bit < 0) || (start_bit > 63)) {
    printf("<P>Error: Invalid start bit (%d)\n", start_bit);
    return -1;
  }
  if ((end_bit < 0) || (end_bit > 63)) {
    printf("<P>Error: Invalid end bit (%d)\n", end_bit);
    return -1;
  }
  if (end_bit < start_bit) {
    printf("<P>Error: End bit (%d) smaller that start bit (%d)\n", end_bit,
           start_bit);
    return -1;
  }
  if (strlen(nh_hex_str) != 16) {
    printf("<P>Invalid 74 bit hex string (%s)\n", nh_hex_str);
    return -1;
  }
  printf("<pre>");
  print_string_as_binary(nh_hex_str, start_bit, end_bit);
  printf("</pre>");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x118(%rbp)
movq   $0x0,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
lea    0xe3d(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1222 <main+0xb2>
mov    -0x10(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    126c <main+0xfc>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1260 <main+0xf0>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    126c <main+0xfc>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x130(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
je     12cf <main+0x15f>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0xf0(%rbp,%rax,1)
jmp    1285 <main+0x115>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cltq
movb   $0x0,-0xf0(%rbp,%rax,1)
cmpl   $0x10,-0x130(%rbp)
jle    1310 <main+0x1a0>
lea    -0xf0(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
lea    -0xf0(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1070 <strspn@plt>
movsbl -0xf0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1355 <main+0x1e5>
lea    -0xf0(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
movb   $0x0,-0x80(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
sub    -0x130(%rbp),%ecx
cmp    %ecx,%eax
jge    13b5 <main+0x245>
lea    -0x80(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    $0x64,%edx
sub    %eax,%edx
sub    $0x1,%edx
lea    0xd5a(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1360 <main+0x1f0>
lea    -0x80(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    $0x64,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1060 <strncat@plt>
lea    -0x80(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xcfb(%rip),%rsi
lea    -0x124(%rbp),%rcx
lea    -0x128(%rbp),%r8
call   1090 <sscanf@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x3,-0x12c(%rbp)
je     1447 <main+0x2d7>
mov    -0x10(%rbp),%rsi
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
cmpl   $0x0,-0x124(%rbp)
jl     146f <main+0x2ff>
cmpl   $0x3f,-0x124(%rbp)
jle    148f <main+0x31f>
mov    -0x124(%rbp),%esi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
cmpl   $0x0,-0x128(%rbp)
jl     14a9 <main+0x339>
cmpl   $0x3f,-0x128(%rbp)
jle    14c9 <main+0x359>
mov    -0x128(%rbp),%esi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
mov    -0x128(%rbp),%eax
cmp    -0x124(%rbp),%eax
jge    1501 <main+0x391>
mov    -0x128(%rbp),%esi
mov    -0x124(%rbp),%edx
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
mov    -0x118(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x10,%eax
je     1537 <main+0x3c7>
mov    -0x118(%rbp),%rsi
lea    0xc9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1572 <main+0x402>
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x118(%rbp),%rdi
mov    -0x124(%rbp),%esi
mov    -0x128(%rbp),%edx
call   1080 <print_string_as_binary@plt>
lea    0xc86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe5b(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x1011(%rip),%rdi
call   1040 <puts@plt>
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1209 <main+0x89>
lea    0x8(%rax),%r12
mov    0x8(%rax),%cl
cmp    $0x30,%cl
jne    11fb <main+0x7b>
mov    0x9(%rax),%cl
or     $0x20,%cl
cmp    $0x78,%cl
jne    1214 <main+0x94>
mov    %rax,%r12
add    $0xa,%r12
mov    0xa(%rax),%cl
cmp    $0x26,%cl
jne    1214 <main+0x94>
movb   $0x0,0x2f(%rsp)
xor    %ebx,%ebx
jmp    1260 <main+0xe0>
lea    0xe2f(%rip),%rdi
xor    %esi,%esi
jmp    1284 <main+0x104>
movabs $0xffffffff00000000,%rax
ff ff ff
xor    %ebx,%ebx
movabs $0x100000000,%rcx
nopw   0x0(%rax,%rax,1)
add    %rcx,%rax
movzbl 0x1(%r12,%rbx,1),%edx
mov    %dl,0x30(%rsp,%rbx,1)
cmpb   $0x26,0x1(%r12,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1230 <main+0xb0>
sar    $0x20,%rax
movb   $0x0,0x30(%rsp,%rax,1)
cmp    $0x10,%ebx
jbe    1260 <main+0xe0>
lea    0xe19(%rip),%rdi
jmp    127f <main+0xff>
lea    0xe3e(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1080 <strspn@plt>
cmpb   $0x0,0x30(%rsp,%rax,1)
je     12a1 <main+0x121>
lea    0xe3d(%rip),%rdi
lea    0x30(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movb   $0x0,0xa0(%rsp)
cmp    $0xf,%ebx
ja     12de <main+0x15e>
add    $0xfffffff0,%ebx
lea    0xa0(%rsp),%r14
lea    0xe20(%rip),%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    $0x63,%edx
sub    %eax,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strncat@plt>
inc    %ebx
jne    12c0 <main+0x140>
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    $0x63,%edx
sub    %eax,%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strncat@plt>
lea    0xddb(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r14,%rdi
call   10a0 <sscanf@plt>
cmp    $0x3,%eax
jne    1337 <main+0x1b7>
mov    0xc(%rsp),%edx
cmp    $0x40,%edx
jb     1346 <main+0x1c6>
lea    0xdfc(%rip),%rdi
mov    %edx,%esi
jmp    1356 <main+0x1d6>
lea    0xdc1(%rip),%rdi
mov    %r12,%rsi
jmp    1284 <main+0x104>
mov    0x8(%rsp),%esi
cmp    $0x40,%esi
jb     1362 <main+0x1e2>
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    128b <main+0x10b>
cmp    %edx,%esi
jae    1379 <main+0x1f9>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    128b <main+0x10b>
lea    0x10(%rsp),%rdi
call   1050 <strlen@plt>
cmp    $0x10,%eax
jne    13bd <main+0x23d>
lea    0xe39(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1090 <print_string_as_binary@plt>
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1290 <main+0x110>
lea    0xde1(%rip),%rdi
lea    0x10(%rsp),%rsi
jmp    1284 <main+0x104>

LLVM IR (-O0):
@.str = [8 x i8] c"%s%c%c\0A\00"
@.str.1 = [42 x i8] c"Content-Type:text/html;charset=iso-8859-1\00"
@.str.2 = [28 x i8] c"<TITLE>Decoded NH </TITLE>\0A\00"
@.str.3 = [13 x i8] c"QUERY_STRING\00"
@.str.4 = [56 x i8] c"<P>Error! Error in passing query string (%p) to script.\00"
@.str.5 = [46 x i8] c"<P>Error! Input hex (0x%s) longer than 64 bit\00"
@.str.6 = [23 x i8] c"0123456789abcdefABCDEF\00"
@.str.7 = [36 x i8] c"<P>Error! Invalide input hex (0x%s)\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [29 x i8] c"%16s&start_bit=%d&end_bit=%d\00"
@.str.10 = [48 x i8] c"<P>Error! 2Invalid query string (%s) to script.\00"
@.str.11 = [34 x i8] c"<P>Error: Invalid start bit (%d)\0A\00"
@.str.12 = [32 x i8] c"<P>Error: Invalid end bit (%d)\0A\00"
@.str.13 = [52 x i8] c"<P>Error: End bit (%d) smaller that start bit (%d)\0A\00"
@.str.14 = [35 x i8] c"<P>Invalid 74 bit hex string (%s)\0A\00"
@.str.15 = [6 x i8] c"<pre>\00"
@.str.16 = [7 x i8] c"</pre>\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca [20 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %3
store i8* null, i8** %4
store i8* null, i8** %8
store i64 0, i64* %9
store i32 0, i32* %10
store i32 0, i32* %11
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 13, i32 10)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%16 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i8*, i8** %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %20)
store i32 -1, i32* %1
br label %157
22: ; preds = %0
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 8
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 48
br i1 %29, label %30, label %45
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 120
br i1 %35, label %42, label %36
36: ; preds = %30
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 88
br i1 %41, label %42, label %45
42: ; preds = %36, %30
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %3
br label %45
45: ; preds = %42, %36, %22
store i32 0, i32* %2
store i32 0, i32* %13
%46 = load i8*, i8** %3
store i8* %46, i8** %4
br label %47
47: ; preds = %52, %45
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 38
br i1 %51, label %52, label %63
52: ; preds = %47
%53 = load i32, i32* %13
%54 = add nsw i32 %53, 1
store i32 %54, i32* %13
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
%57 = load i8*, i8** %4
%58 = load i8, i8* %57
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %61
store i8 %58, i8* %62
br label %47
63: ; preds = %47
%64 = load i32, i32* %2
%65 = add nsw i32 %64, -1
store i32 %65, i32* %2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %66
store i8 0, i8* %67
%68 = load i32, i32* %13
%69 = icmp sgt i32 %68, 16
br i1 %69, label %70, label %73
70: ; preds = %63
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %71)
store i32 -1, i32* %1
br label %157
73: ; preds = %63
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%75 = call i64 @strspn(i8* %74, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %81)
store i32 -1, i32* %1
br label %157
83: ; preds = %73
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 0, i8* %84
store i32 0, i32* %2
br label %85
85: ; preds = %97, %83
%86 = load i32, i32* %2
%87 = load i32, i32* %13
%88 = sub nsw i32 16, %87
%89 = icmp slt i32 %86, %88
br i1 %89, label %90, label %100
90: ; preds = %85
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
%94 = sub nsw i32 100, %93
%95 = sub nsw i32 %94, 1
%96 = call i32 @strncat(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %90
%98 = load i32, i32* %2
%99 = add nsw i32 %98, 1
store i32 %99, i32* %2
br label %85
100: ; preds = %85
%101 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%102 = load i8*, i8** %3
%103 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%104 = call i32 @strlen(i8* %103)
%105 = sub nsw i32 100, %104
%106 = sub nsw i32 %105, 1
%107 = call i32 @strncat(i8* %101, i8* %102, i32 %106)
%108 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%109 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%110 = call i32 @sscanf(i8* %108, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %109, i32* %10, i32* %11)
store i32 %110, i32* %12
%111 = load i32, i32* %12
%112 = icmp ne i32 %111, 3
br i1 %112, label %113, label %116
113: ; preds = %100
%114 = load i8*, i8** %3
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i8* %114)
store i32 -1, i32* %1
br label %157
116: ; preds = %100
%117 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
store i8* %117, i8** %8
%118 = load i32, i32* %10
%119 = icmp slt i32 %118, 0
br i1 %119, label %123, label %120
120: ; preds = %116
%121 = load i32, i32* %10
%122 = icmp sgt i32 %121, 63
br i1 %122, label %123, label %126
123: ; preds = %120, %116
%124 = load i32, i32* %10
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %124)
store i32 -1, i32* %1
br label %157
126: ; preds = %120
%127 = load i32, i32* %11
%128 = icmp slt i32 %127, 0
br i1 %128, label %132, label %129
129: ; preds = %126
%130 = load i32, i32* %11
%131 = icmp sgt i32 %130, 63
br i1 %131, label %132, label %135
132: ; preds = %129, %126
%133 = load i32, i32* %11
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i32 %133)
store i32 -1, i32* %1
br label %157
135: ; preds = %129
%136 = load i32, i32* %11
%137 = load i32, i32* %10
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %143
139: ; preds = %135
%140 = load i32, i32* %11
%141 = load i32, i32* %10
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.13, i64 0, i64 0), i32 %140, i32 %141)
store i32 -1, i32* %1
br label %157
143: ; preds = %135
%144 = load i8*, i8** %8
%145 = call i32 @strlen(i8* %144)
%146 = icmp ne i32 %145, 16
br i1 %146, label %147, label %150
147: ; preds = %143
%148 = load i8*, i8** %8
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %148)
store i32 -1, i32* %1
br label %157
150: ; preds = %143
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
%152 = load i8*, i8** %8
%153 = load i32, i32* %10
%154 = load i32, i32* %11
%155 = call i32 @print_string_as_binary(i8* %152, i32 %153, i32 %154)
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %1
br label %157
157: ; preds = %150, %147, %139, %132, %123, %113, %80, %70, %19
%158 = load i32, i32* %1
ret i32 %158
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s%c%c\0A\00"
@.str.1 = [42 x i8] c"Content-Type:text/html;charset=iso-8859-1\00"
@.str.3 = [13 x i8] c"QUERY_STRING\00"
@.str.4 = [56 x i8] c"<P>Error! Error in passing query string (%p) to script.\00"
@.str.5 = [46 x i8] c"<P>Error! Input hex (0x%s) longer than 64 bit\00"
@.str.6 = [23 x i8] c"0123456789abcdefABCDEF\00"
@.str.7 = [36 x i8] c"<P>Error! Invalide input hex (0x%s)\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [29 x i8] c"%16s&start_bit=%d&end_bit=%d\00"
@.str.10 = [48 x i8] c"<P>Error! 2Invalid query string (%s) to script.\00"
@.str.11 = [34 x i8] c"<P>Error: Invalid start bit (%d)\0A\00"
@.str.12 = [32 x i8] c"<P>Error: Invalid end bit (%d)\0A\00"
@.str.13 = [52 x i8] c"<P>Error: End bit (%d) smaller that start bit (%d)\0A\00"
@.str.14 = [35 x i8] c"<P>Invalid 74 bit hex string (%s)\0A\00"
@.str.15 = [6 x i8] c"<pre>\00"
@.str.16 = [7 x i8] c"</pre>\00"
@str = [27 x i8] c"<TITLE>Decoded NH </TITLE>\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 13, i32 10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %105
17: ; preds = %0
%18 = getelementptr inbounds i8, i8* %13, i64 8
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 48
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %13, i64 9
%23 = load i8, i8* %22
switch i8 %23, label %33 [
i8 120, label %24
i8 88, label %24
]
24: ; preds = %21, %21
%25 = getelementptr inbounds i8, i8* %13, i64 10
%26 = load i8, i8* %25
br label %27
27: ; preds = %24, %17
%28 = phi i8 [ %26, %24 ], [ %19, %17 ]
%29 = phi i8* [ %25, %24 ], [ %18, %17 ]
%30 = icmp eq i8 %28, 38
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 -1
store i8 0, i8* %32
br label %52
33: ; preds = %21, %27
%34 = phi i8* [ %29, %27 ], [ %18, %21 ]
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %38, %35 ]
%37 = phi i8* [ %34, %33 ], [ %39, %35 ]
%38 = add nuw i64 %36, 1
%39 = getelementptr inbounds i8, i8* %37, i64 1
%40 = load i8, i8* %39
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %36
store i8 %40, i8* %41
%42 = load i8, i8* %39
%43 = icmp eq i8 %42, 38
br i1 %43, label %44, label %35
44: ; preds = %35
%45 = trunc i64 %38 to i32
%46 = shl i64 %36, 32
%47 = ashr exact i64 %46, 32
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %47
store i8 0, i8* %48
%49 = icmp ugt i32 %45, 16
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %7)
br label %105
52: ; preds = %31, %44
%53 = phi i32 [ 0, %31 ], [ %45, %44 ]
%54 = phi i8* [ %29, %31 ], [ %34, %44 ]
%55 = call i64 @strspn(i8* %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %52
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %7)
br label %105
61: ; preds = %52
store i8 0, i8* %6
%62 = icmp ult i32 %53, 16
br i1 %62, label %63, label %72
63: ; preds = %61
%64 = sub nuw nsw i32 16, %53
br label %65
65: ; preds = %63, %65
%66 = phi i32 [ %70, %65 ], [ 0, %63 ]
%67 = call i32 @strlen(i8* %6)
%68 = sub i32 99, %67
%69 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %68)
%70 = add nuw nsw i32 %66, 1
%71 = icmp eq i32 %70, %64
br i1 %71, label %72, label %65
72: ; preds = %65, %61
%73 = call i32 @strlen(i8* %6)
%74 = sub i32 99, %73
%75 = call i32 @strncat(i8* %6, i8* %54, i32 %74)
%76 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %8, i32* %4, i32* %5)
%77 = icmp eq i32 %76, 3
br i1 %77, label %80, label %78
78: ; preds = %72
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i8* %54)
br label %105
80: ; preds = %72
%81 = load i32, i32* %4
%82 = icmp ugt i32 %81, 63
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i32 %81)
br label %105
85: ; preds = %80
%86 = load i32, i32* %5
%87 = icmp ugt i32 %86, 63
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i32 %86)
br label %105
90: ; preds = %85
%91 = icmp ult i32 %86, %81
br i1 %91, label %92, label %94
92: ; preds = %90
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.13, i64 0, i64 0), i32 %86, i32 %81)
br label %105
94: ; preds = %90
%95 = call i32 @strlen(i8* %8)
%96 = icmp eq i32 %95, 16
br i1 %96, label %99, label %97
97: ; preds = %94
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %8)
br label %105
99: ; preds = %94
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
%101 = load i32, i32* %4
%102 = load i32, i32* %5
%103 = call i32 @print_string_as_binary(i8* %8, i32 %101, i32 %102)
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
br label %105
105: ; preds = %99, %97, %92, %88, %83, %78, %59, %50, %15
%106 = phi i32 [ -1, %15 ], [ -1, %50 ], [ -1, %59 ], [ -1, %78 ], [ -1, %83 ], [ -1, %88 ], [ -1, %92 ], [ -1, %97 ], [ 0, %99 ]
ret i32 %106
}