#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 curlGetValue(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *strtok(char *, char const *);
int main(int argc, char **argv) {
  printf("Content-Type: text/plain;charset=us-ascii\n\n");
  char *data = NULL;
  int len;
  data = getenv("QUERY_STRING");
  if (!data) {
    printf("Internal problem detected\n");
    return 0;
  }
  len = strlen(data);
  if (len < 14)
    goto end;
  if (len > 64)
    len = 64;
  char buffer[64];
  memset(buffer, 0, 60);
  memcpy(buffer, data, len);
  const char s[2] = "=";
  char *token;
  token = strtok(buffer, s);
  if (!token)
    goto end;
  token = strtok(NULL, s);
  if (!token)
    goto end;
  char order[16];
  int size = 0;
  size = strlen(token);
  if (size > 16)
    size = 16;
  memset(order, 0, 16);
  memcpy(order, token, size);
  char url[256];
  memset(url, 0, 250);
  sprintf(url, "http://rest:9000/getOrderValue?order=%s&parameter=amount%s",
          order);
  int res;
  char result[64];
  memset(result, 0, 60);
  res = curlGetValue(url, result);
  if (res)
    goto end;
  printf("%s\n", result);
end:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x64>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1354 <main+0x1d4>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xe,-0x1c(%rbp)
jge    11ff <main+0x7f>
jmp    134d <main+0x1cd>
cmpl   $0x40,-0x1c(%rbp)
jle    1210 <main+0x90>
movl   $0x40,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1070 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <memcpy@plt>
mov    0xe1d(%rip),%ax
mov    %ax,-0x62(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x62(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    125c <main+0xdc>
jmp    134d <main+0x1cd>
lea    -0x62(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    127d <main+0xfd>
jmp    134d <main+0x1cd>
movl   $0x0,-0x84(%rbp)
mov    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x10,-0x84(%rbp)
jle    12ad <main+0x12d>
movl   $0x10,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1080 <memcpy@plt>
lea    -0x190(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
lea    -0x190(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd61(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1070 <memset@plt>
lea    -0x190(%rbp),%rdi
lea    -0x1e0(%rbp),%rsi
call   1050 <curlGetValue@plt>
mov    %eax,-0x194(%rbp)
cmpl   $0x0,-0x194(%rbp)
je     1338 <main+0x1b8>
jmp    134d <main+0x1cd>
lea    -0x1e0(%rbp),%rsi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12aa <main+0x12a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0xe,%eax
jl     12b6 <main+0x136>
cmp    $0x40,%eax
mov    $0x40,%ebp
cmovb  %eax,%ebp
lea    0x60(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
movw   $0x3d,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %r14,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     12b6 <main+0x136>
lea    0xe(%rsp),%rsi
xor    %edi,%edi
call   1090 <strtok@plt>
test   %rax,%rax
je     12b6 <main+0x136>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
cmp    $0x10,%eax
mov    $0x10,%eax
cmovge %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1070 <memset@plt>
lea    0xd98(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <curlGetValue@plt>
test   %eax,%eax
jne    12b6 <main+0x136>
lea    0x20(%rsp),%rdi
jmp    12b1 <main+0x131>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Content-Type: text/plain;charset=us-ascii\0A\0A\00"
@.str.1 = [13 x i8] c"QUERY_STRING\00"
@.str.2 = [27 x i8] c"Internal problem detected\0A\00"
@__const.main.s = [2 x i8] c"=\00"
@.str.3 = [59 x i8] c"http://rest:9000/getOrderValue?order=%s&parameter=amount%s\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca [2 x i8]
%10 = alloca i8*
%11 = alloca [16 x i8]
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca i32
%15 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
%17 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %82
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 14
br i1 %26, label %27, label %28
27: ; preds = %22
br label %81
28: ; preds = %22
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 64
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 64, i32* %7
br label %32
32: ; preds = %31, %28
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 60)
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = bitcast [2 x i8]* %9 to i8*
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%42 = call i8* @strtok(i8* %40, i8* %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %46, label %45
45: ; preds = %32
br label %81
46: ; preds = %32
%47 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%48 = call i8* @strtok(i8* null, i8* %47)
store i8* %48, i8** %10
%49 = load i8*, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %52, label %51
51: ; preds = %46
br label %81
52: ; preds = %46
store i32 0, i32* %12
%53 = load i8*, i8** %10
%54 = call i32 @strlen(i8* %53)
store i32 %54, i32* %12
%55 = load i32, i32* %12
%56 = icmp sgt i32 %55, 16
br i1 %56, label %57, label %58
57: ; preds = %52
store i32 16, i32* %12
br label %58
58: ; preds = %57, %52
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%60 = call i32 @memset(i8* %59, i32 0, i32 16)
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%62 = load i8*, i8** %10
%63 = load i32, i32* %12
%64 = call i32 @memcpy(i8* %61, i8* %62, i32 %63)
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%66 = call i32 @memset(i8* %65, i32 0, i32 250)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%68 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%69 = call i32 @sprintf(i8* %67, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %68)
%70 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%71 = call i32 @memset(i8* %70, i32 0, i32 60)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%74 = call i32 @curlGetValue(i8* %72, i8* %73)
store i32 %74, i32* %14
%75 = load i32, i32* %14
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %58
br label %81
78: ; preds = %58
%79 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %78, %77, %51, %45, %27
store i32 0, i32* %3
br label %82
82: ; preds = %81, %20
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [59 x i8] c"http://rest:9000/getOrderValue?order=%s&parameter=amount%s\00"
@str = [43 x i8] c"Content-Type: text/plain;charset=us-ascii\0A\00"
@str.5 = [26 x i8] c"Internal problem detected\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = alloca i16
%5 = alloca [16 x i8]
%6 = alloca [256 x i8]
%7 = alloca [64 x i8]
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
br label %44
13: ; preds = %2
%14 = tail call i32 @strlen(i8* %9)
%15 = icmp slt i32 %14, 14
br i1 %15, label %44, label %16
16: ; preds = %13
%17 = icmp ult i32 %14, 64
%18 = select i1 %17, i32 %14, i32 64
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 60)
%21 = call i32 @memcpy(i8* %19, i8* %9, i32 %18)
store i16 61, i16* %4
%22 = bitcast i16* %4 to i8*
%23 = call i8* @strtok(i8* %19, i8* %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %44, label %25
25: ; preds = %16
%26 = call i8* @strtok(i8* null, i8* %22)
%27 = icmp eq i8* %26, null
br i1 %27, label %44, label %28
28: ; preds = %25
%29 = call i32 @strlen(i8* %26)
%30 = icmp slt i32 %29, 16
%31 = select i1 %30, i32 %29, i32 16
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 16)
%34 = call i32 @memcpy(i8* %32, i8* %26, i32 %31)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%36 = call i32 @memset(i8* %35, i32 0, i32 250)
%37 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 60)
%40 = call i32 @curlGetValue(i8* %35, i8* %38)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %28
%43 = call i32 @puts(i8* %38)
br label %44
44: ; preds = %42, %13, %16, %25, %28, %11
ret i32 0
}