#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 atoi(char *);
scalar_t__ decode_query(char *, char *, char *, int *);
int fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char qbuf[1024], val[1024];
  int len = 1024;
  int size = 0;
  if (argc < 2)
    return -1;
  char *key = argv[1];
  if (argc > 2)
    len = atoi(argv[2]);
  if ((len = fread(qbuf, 1, len, stdin)) > 0) {
    qbuf[len] = 0;
    if (decode_query(qbuf, key, val, &size) == 0) {
      fwrite(val, 1, size, stdout);
      return 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x400,-0x814(%rbp)
movl   $0x0,-0x818(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1183 <main+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <main+0x110>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x820(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11af <main+0x6f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x814(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x814(%rbp),%edx
mov    0x2e25(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x814(%rbp)
cmp    $0x0,%eax
jle    1249 <main+0x109>
movslq -0x814(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
mov    -0x820(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    -0x818(%rbp),%rcx
call   1040 <decode_query@plt>
cmp    $0x0,%rax
jne    1244 <main+0x104>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%edx
mov    0x2dac(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
movl   $0x0,-0x4(%rbp)
jmp    1250 <main+0x110>
jmp    1249 <main+0x109>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x818,%rsp
movl   $0x0,0xc(%rsp)
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     11d5 <main+0x95>
mov    0x8(%rsi),%r14
mov    $0x400,%edx
je     1172 <main+0x32>
mov    0x10(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
test   %eax,%eax
jle    11d5 <main+0x95>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%rdi
lea    0x410(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r14,%rsi
call   1040 <decode_query@plt>
test   %rax,%rax
jne    11d5 <main+0x95>
mov    0xc(%rsp),%edx
mov    0x2e19(%rip),%rax
mov    (%rax),%ecx
lea    0x410(%rsp),%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1024, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %47
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %10
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %20, %14
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %8
%28 = load i32, i32* @stdin
%29 = call i32 @fread(i8* %26, i32 1, i32 %27, i32 %28)
store i32 %29, i32* %8
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %25
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %33
store i8 0, i8* %34
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = load i8*, i8** %10
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = call i64 @decode_query(i8* %35, i8* %36, i8* %37, i32* %9)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %31
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = load i32, i32* %9
%43 = load i32, i32* @stdout
%44 = call i32 @fwrite(i8* %41, i32 1, i32 %42, i32 %43)
store i32 0, i32* %3
br label %47
45: ; preds = %31
br label %46
46: ; preds = %45, %25
store i32 -1, i32* %3
br label %47
47: ; preds = %46, %40, %13
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = icmp slt i32 %0, 2
br i1 %9, label %32, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = icmp eq i32 %0, 2
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ %17, %14 ], [ 1024, %10 ]
%20 = load i32, i32* @stdin
%21 = call i32 @fread(i8* %6, i32 1, i32 %19, i32 %20)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = zext i32 %21 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @decode_query(i8* %6, i8* %12, i8* %7, i32* %5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* %5
%30 = load i32, i32* @stdout
%31 = call i32 @fwrite(i8* %7, i32 1, i32 %29, i32 %30)
br label %32
32: ; preds = %28, %23, %18, %2
%33 = phi i32 [ -1, %2 ], [ 0, %28 ], [ -1, %23 ], [ -1, %18 ]
ret i32 %33
}