#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 curl(char *);
scalar_t__ getCookie(char *);
int /*<<< orphan*/ getDocumentRoot(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int strlen(char *);
char *strtok(char *, char const *);
int main(int argc, char **argv) {
  char root[128];
  memset(root, 0, 128);
  getDocumentRoot(getenv("HTTP_REFERER"), root);
  char location[256];
  memset(location, 0, 256);
  sprintf(location, "%s/display_cart.html", root);
  char cookie[128];
  float result = 0;
  memset(cookie, 0, 128);
  if (getCookie(cookie))
    goto end;
  char *data = NULL;
  int len;
  data = getenv("QUERY_STRING");
  if (!data)
    return 0;
  len = strlen(data);
  if (len < 9)
    goto end;
  if (len > 10)
    len = 10;
  char buffer[10];
  memset(buffer, 0, 10);
  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 zip[10];
  int size = 0;
  size = strlen(token);
  if (size > 10)
    size = 10;
  memset(zip, 0, 10);
  memcpy(zip, token, size);
  char url[256];
  memset(url, 0, 256);
  sprintf(url,
          "http://rest:9000/setCookieValue?cookie=%s&parameter=zip&value=%s",
          cookie, zip);
  int res;
  res = curl(url);
end:
  printf("Location: %s\r\n\r\n", location);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe2d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    -0x90(%rbp),%rsi
call   10c0 <getDocumentRoot@plt>
lea    -0x190(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x190(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x214(%rbp)
ff
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x210(%rbp),%rdi
call   1070 <getCookie@plt>
cmp    $0x0,%rax
je     124f <main+0xaf>
jmp    13fa <main+0x25a>
movq   $0x0,-0x220(%rbp)
lea    0xdc1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    1287 <main+0xe7>
movl   $0x0,-0x4(%rbp)
jmp    1414 <main+0x274>
mov    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x9,-0x224(%rbp)
jge    12ab <main+0x10b>
jmp    13fa <main+0x25a>
cmpl   $0xa,-0x224(%rbp)
jle    12c2 <main+0x122>
movl   $0xa,-0x224(%rbp)
lea    -0x22e(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
lea    -0x22e(%rbp),%rdi
mov    -0x220(%rbp),%rsi
mov    -0x224(%rbp),%edx
call   1090 <memcpy@plt>
mov    0xd3a(%rip),%ax
mov    %ax,-0x230(%rbp)
lea    -0x22e(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1329 <main+0x189>
jmp    13fa <main+0x25a>
lea    -0x230(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <strtok@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1353 <main+0x1b3>
jmp    13fa <main+0x25a>
movl   $0x0,-0x248(%rbp)
mov    -0x238(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x248(%rbp)
cmpl   $0xa,-0x248(%rbp)
jle    1386 <main+0x1e6>
movl   $0xa,-0x248(%rbp)
lea    -0x242(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
lea    -0x242(%rbp),%rdi
mov    -0x238(%rbp),%rsi
mov    -0x248(%rbp),%edx
call   1090 <memcpy@plt>
lea    -0x350(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x350(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    -0x242(%rbp),%rcx
lea    0xc50(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x350(%rbp),%rdi
call   1080 <curl@plt>
mov    %eax,-0x354(%rbp)
lea    -0x190(%rbp),%rsi
lea    0xc6a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x320,%rsp
lea    0x1a0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   10c0 <getDocumentRoot@plt>
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe16(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1070 <getCookie@plt>
test   %rax,%rax
je     1247 <main+0xa7>
lea    0xe44(%rip),%rdi
lea    0xa0(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x320,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1239 <main+0x99>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x9,%eax
jl     1225 <main+0x85>
mov    %eax,%ebp
mov    $0xa,%eax
cmova  %eax,%ebp
lea    0x16(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1090 <memcpy@plt>
movw   $0x3d,0xa(%rsp)
lea    0xa(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1225 <main+0x85>
lea    0xa(%rsp),%rsi
xor    %edi,%edi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1225 <main+0x85>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
mov    $0xa,%eax
cmovge %eax,%ebp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1090 <memcpy@plt>
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xd13(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <curl@plt>
jmp    1225 <main+0x85>

LLVM IR (-O0):
@.str = [13 x i8] c"HTTP_REFERER\00"
@.str.1 = [21 x i8] c"%s/display_cart.html\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@__const.main.s = [2 x i8] c"=\00"
@.str.3 = [65 x i8] c"http://rest:9000/setCookieValue?cookie=%s&parameter=zip&value=%s\00"
@.str.4 = [17 x i8] c"Location: %s\0D\0A\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca [256 x i8]
%8 = alloca [128 x i8]
%9 = alloca float
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [10 x i8]
%13 = alloca [2 x i8]
%14 = alloca i8*
%15 = alloca [10 x i8]
%16 = alloca i32
%17 = alloca [256 x i8]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 128)
%21 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = call i32 @getDocumentRoot(i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 256)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store float 0.000000e+00, float* %9
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 128)
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%32 = call i64 @getCookie(i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %2
br label %91
35: ; preds = %2
store i8* null, i8** %10
%36 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %35
store i32 0, i32* %3
br label %94
40: ; preds = %35
%41 = load i8*, i8** %10
%42 = call i32 @strlen(i8* %41)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = icmp slt i32 %43, 9
br i1 %44, label %45, label %46
45: ; preds = %40
br label %91
46: ; preds = %40
%47 = load i32, i32* %11
%48 = icmp sgt i32 %47, 10
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 10, i32* %11
br label %50
50: ; preds = %49, %46
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i32 0, i32 10)
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%54 = load i8*, i8** %10
%55 = load i32, i32* %11
%56 = call i32 @memcpy(i8* %53, i8* %54, i32 %55)
%57 = bitcast [2 x i8]* %13 to i8*
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%59 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%60 = call i8* @strtok(i8* %58, i8* %59)
store i8* %60, i8** %14
%61 = load i8*, i8** %14
%62 = icmp ne i8* %61, null
br i1 %62, label %64, label %63
63: ; preds = %50
br label %91
64: ; preds = %50
%65 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%66 = call i8* @strtok(i8* null, i8* %65)
store i8* %66, i8** %14
%67 = load i8*, i8** %14
%68 = icmp ne i8* %67, null
br i1 %68, label %70, label %69
69: ; preds = %64
br label %91
70: ; preds = %64
store i32 0, i32* %16
%71 = load i8*, i8** %14
%72 = call i32 @strlen(i8* %71)
store i32 %72, i32* %16
%73 = load i32, i32* %16
%74 = icmp sgt i32 %73, 10
br i1 %74, label %75, label %76
75: ; preds = %70
store i32 10, i32* %16
br label %76
76: ; preds = %75, %70
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %15, i64 0, i64 0
%78 = call i32 @memset(i8* %77, i32 0, i32 10)
%79 = getelementptr inbounds [10 x i8], [10 x i8]* %15, i64 0, i64 0
%80 = load i8*, i8** %14
%81 = load i32, i32* %16
%82 = call i32 @memcpy(i8* %79, i8* %80, i32 %81)
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%84 = call i32 @memset(i8* %83, i32 0, i32 256)
%85 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%86 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%87 = getelementptr inbounds [10 x i8], [10 x i8]* %15, i64 0, i64 0
%88 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %85, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i8* %86, i8* %87)
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%90 = call i32 @curl(i8* %89)
store i32 %90, i32* %18
br label %91
91: ; preds = %76, %69, %63, %45, %34
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%93 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %91, %39
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [13 x i8] c"HTTP_REFERER\00"
@.str.1 = [21 x i8] c"%s/display_cart.html\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [65 x i8] c"http://rest:9000/setCookieValue?cookie=%s&parameter=zip&value=%s\00"
@.str.4 = [17 x i8] c"Location: %s\0D\0A\0D\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [256 x i8]
%5 = alloca [128 x i8]
%6 = alloca [10 x i8]
%7 = alloca i16
%8 = alloca [10 x i8]
%9 = alloca [256 x i8]
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 128)
%12 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @getDocumentRoot(i8* %12, i8* %10)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 256)
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 128)
%19 = call i64 @getCookie(i8* %17)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %50
21: ; preds = %2
%22 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %52, label %24
24: ; preds = %21
%25 = call i32 @strlen(i8* %22)
%26 = icmp slt i32 %25, 9
br i1 %26, label %50, label %27
27: ; preds = %24
%28 = icmp ult i32 %25, 10
%29 = select i1 %28, i32 %25, i32 10
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%31 = call i32 @memset(i8* %30, i32 0, i32 10)
%32 = call i32 @memcpy(i8* %30, i8* %22, i32 %29)
store i16 61, i16* %7
%33 = bitcast i16* %7 to i8*
%34 = call i8* @strtok(i8* %30, i8* %33)
%35 = icmp eq i8* %34, null
br i1 %35, label %50, label %36
36: ; preds = %27
%37 = call i8* @strtok(i8* null, i8* %33)
%38 = icmp eq i8* %37, null
br i1 %38, label %50, label %39
39: ; preds = %36
%40 = call i32 @strlen(i8* %37)
%41 = icmp slt i32 %40, 10
%42 = select i1 %41, i32 %40, i32 10
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 10)
%45 = call i32 @memcpy(i8* %43, i8* %37, i32 %42)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i32 0, i32 256)
%48 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %43)
%49 = call i32 @curl(i8* %46)
br label %50
50: ; preds = %36, %27, %24, %2, %39
%51 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %52
52: ; preds = %21, %50
ret i32 0
}