#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, 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 order_formatted[20];
  char order_formatted_1[4], order_formatted_2[4], order_formatted_3[4];
  memset(order_formatted, 0, 20);
  memset(order_formatted_1, 0, 4);
  memset(order_formatted_2, 0, 4);
  memset(order_formatted_3, 0, 4);
  memcpy(order_formatted_1, order, 4);
  memcpy(order_formatted_2, order + 4, 4);
  memcpy(order_formatted_3, order + 8, 4);
  sprintf(order_formatted, "%s-%s-%s", order_formatted_1, order_formatted_2,
          order_formatted_3);
  printf("%s\n", order_formatted);
end:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x18(%rbp)
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <main+0x64>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1397 <main+0x227>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xe,-0x1c(%rbp)
jge    11ef <main+0x7f>
jmp    1390 <main+0x220>
cmpl   $0x40,-0x1c(%rbp)
jle    1200 <main+0x90>
movl   $0x40,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1060 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <memcpy@plt>
mov    0xe2d(%rip),%ax
mov    %ax,-0x62(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x62(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    124c <main+0xdc>
jmp    1390 <main+0x220>
lea    -0x62(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    126d <main+0xfd>
jmp    1390 <main+0x220>
movl   $0x0,-0x84(%rbp)
mov    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x10,-0x84(%rbp)
jle    129d <main+0x12d>
movl   $0x10,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1070 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0xa4(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0xa8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0xac(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0xa4(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    -0xa8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    -0xac(%rbp),%rdi
lea    -0x80(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa4(%rbp),%rdx
lea    -0xa8(%rbp),%rcx
lea    -0xac(%rbp),%r8
lea    0xce0(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12ee <main+0x17e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0xe,%eax
jl     12fa <main+0x18a>
cmp    $0x40,%eax
mov    $0x40,%ebp
cmovb  %eax,%ebp
lea    0x40(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
movw   $0x3d,0x2(%rsp)
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     12fa <main+0x18a>
lea    0x2(%rsp),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     12fa <main+0x18a>
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),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x8(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0x14(%rsp),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0xd35(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   1090 <sprintf@plt>
mov    %r14,%rdi
jmp    12f5 <main+0x185>
lea    0xd4c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 = [9 x i8] c"%s-%s-%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 [20 x i8]
%14 = alloca [4 x i8]
%15 = alloca [4 x i8]
%16 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
%18 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %2
%22 = 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 %93
23: ; preds = %2
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 14
br i1 %27, label %28, label %29
28: ; preds = %23
br label %92
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 64
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 64, i32* %7
br label %33
33: ; preds = %32, %29
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 60)
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = call i32 @memcpy(i8* %36, i8* %37, i32 %38)
%40 = bitcast [2 x i8]* %9 to i8*
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%42 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%43 = call i8* @strtok(i8* %41, i8* %42)
store i8* %43, i8** %10
%44 = load i8*, i8** %10
%45 = icmp ne i8* %44, null
br i1 %45, label %47, label %46
46: ; preds = %33
br label %92
47: ; preds = %33
%48 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%49 = call i8* @strtok(i8* null, i8* %48)
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %53, label %52
52: ; preds = %47
br label %92
53: ; preds = %47
store i32 0, i32* %12
%54 = load i8*, i8** %10
%55 = call i32 @strlen(i8* %54)
store i32 %55, i32* %12
%56 = load i32, i32* %12
%57 = icmp sgt i32 %56, 16
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 16, i32* %12
br label %59
59: ; preds = %58, %53
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%61 = call i32 @memset(i8* %60, i32 0, i32 16)
%62 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%63 = load i8*, i8** %10
%64 = load i32, i32* %12
%65 = call i32 @memcpy(i8* %62, i8* %63, i32 %64)
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 20)
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
%69 = call i32 @memset(i8* %68, i32 0, i32 4)
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%71 = call i32 @memset(i8* %70, i32 0, i32 4)
%72 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%73 = call i32 @memset(i8* %72, i32 0, i32 4)
%74 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%76 = call i32 @memcpy(i8* %74, i8* %75, i32 4)
%77 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%79 = getelementptr inbounds i8, i8* %78, i64 4
%80 = call i32 @memcpy(i8* %77, i8* %79, i32 4)
%81 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%82 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%83 = getelementptr inbounds i8, i8* %82, i64 8
%84 = call i32 @memcpy(i8* %81, i8* %83, i32 4)
%85 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
%87 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%88 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%89 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %86, i8* %87, i8* %88)
%90 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %59, %52, %46, %28
store i32 0, i32* %3
br label %93
93: ; preds = %92, %21
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [9 x i8] c"%s-%s-%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 [20 x i8]
%7 = alloca [4 x i8]
%8 = alloca [4 x i8]
%9 = alloca [4 x i8]
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
br label %52
15: ; preds = %2
%16 = tail call i32 @strlen(i8* %11)
%17 = icmp slt i32 %16, 14
br i1 %17, label %52, label %18
18: ; preds = %15
%19 = icmp ult i32 %16, 64
%20 = select i1 %19, i32 %16, i32 64
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 60)
%23 = call i32 @memcpy(i8* %21, i8* %11, i32 %20)
store i16 61, i16* %4
%24 = bitcast i16* %4 to i8*
%25 = call i8* @strtok(i8* %21, i8* %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %52, label %27
27: ; preds = %18
%28 = call i8* @strtok(i8* null, i8* %24)
%29 = icmp eq i8* %28, null
br i1 %29, label %52, label %30
30: ; preds = %27
%31 = call i32 @strlen(i8* %28)
%32 = icmp slt i32 %31, 16
%33 = select i1 %32, i32 %31, i32 16
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 16)
%36 = call i32 @memcpy(i8* %34, i8* %28, i32 %33)
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 20)
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 4)
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 4)
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 4)
%45 = call i32 @memcpy(i8* %39, i8* %34, i32 4)
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 4
%47 = call i32 @memcpy(i8* %41, i8* %46, i32 4)
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 8
%49 = call i32 @memcpy(i8* %43, i8* %48, i32 4)
%50 = call i32 @sprintf(i8* %37, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %41, i8* %43)
%51 = call i32 @puts(i8* %37)
br label %52
52: ; preds = %30, %15, %18, %27, %13
ret i32 0
}