#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, long *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ unencode(char *, char *, char *);
int main(void) {
  char *lenstr;
  char input[80 + 5 + 2], data[80 + 5 + 2];
  long len;
  printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1", 13, 10);
  printf("<TITLE>Response</TITLE>\n");
  lenstr = getenv("CONTENT_LENGTH");
  if (lenstr == NULL || sscanf(lenstr, "%ld", &len) != 1 || len > 80)
    printf("<P>Error in invocation - wrong FORM probably.");
  else {
    FILE *f;
    fgets(input, len + 1, stdin);
    unencode(input + 5, input + len, data);
    f = fopen("../data/data.txt", "a");
    if (f == NULL)
      printf("<P>Sorry, cannot store your data.");
    else
      fputs(data, f);
    fclose(f);
    printf("<P>Thank you! Your contribution has been stored.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1208 <main+0x88>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
lea    -0xd8(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    1208 <main+0x88>
cmpq   $0x50,-0xd8(%rbp)
50
jle    121b <main+0x9b>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12bf <main+0x13f>
lea    -0x70(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
add    $0x1,%rsi
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
call   1080 <fgets@plt>
lea    -0x70(%rbp),%rdi
add    $0x5,%rdi
lea    -0x70(%rbp),%rsi
add    -0xd8(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1040 <unencode@plt>
lea    0xe2e(%rip),%rdi
lea    0xe38(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xe0(%rbp)
cmpq   $0x0,-0xe0(%rbp)
jne    1292 <main+0x112>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a5 <main+0x125>
lea    -0xd0(%rbp),%rdi
mov    -0xe0(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0xe0(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
lea    0xe61(%rip),%rdi
lea    0xe62(%rip),%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xf1b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe68(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe6f(%rip),%rbx
test   %rax,%rax
je     127f <main+0xef>
lea    0xe5b(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    127f <main+0xef>
mov    0x8(%rsp),%rsi
cmp    $0x50,%rsi
jg     127f <main+0xef>
add    $0x1,%rsi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <fgets@plt>
lea    0x75(%rsp),%rdi
add    0x8(%rsp),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
call   1050 <unencode@plt>
lea    0xe34(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1262 <main+0xd2>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <fputs@plt>
jmp    1270 <main+0xe0>
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xe29(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
ret

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 = [25 x i8] c"<TITLE>Response</TITLE>\0A\00"
@.str.3 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.4 = [4 x i8] c"%ld\00"
@.str.5 = [46 x i8] c"<P>Error in invocation - wrong FORM probably.\00"
@stdin = global i32 0
@.str.6 = [17 x i8] c"../data/data.txt\00"
@.str.7 = [2 x i8] c"a\00"
@.str.8 = [34 x i8] c"<P>Sorry, cannot store your data.\00"
@.str.9 = [49 x i8] c"<P>Thank you! Your contribution has been stored.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [87 x i8]
%4 = alloca [87 x i8]
%5 = alloca i64
%6 = alloca i32*
store i32 0, i32* %1
%7 = 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)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%9 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %0
%13 = load i8*, i8** %2
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %5)
%15 = icmp ne i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i64, i64* %5
%18 = icmp sgt i64 %17, 80
br i1 %18, label %19, label %21
19: ; preds = %16, %12, %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
br label %47
21: ; preds = %16
%22 = getelementptr inbounds [87 x i8], [87 x i8]* %3, i64 0, i64 0
%23 = load i64, i64* %5
%24 = add nsw i64 %23, 1
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %22, i64 %24, i32 %25)
%27 = getelementptr inbounds [87 x i8], [87 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 5
%29 = getelementptr inbounds [87 x i8], [87 x i8]* %3, i64 0, i64 0
%30 = load i64, i64* %5
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = getelementptr inbounds [87 x i8], [87 x i8]* %4, i64 0, i64 0
%33 = call i32 @unencode(i8* %28, i8* %31, i8* %32)
%34 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %34, i32** %6
%35 = load i32*, i32** %6
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
br label %43
39: ; preds = %21
%40 = getelementptr inbounds [87 x i8], [87 x i8]* %4, i64 0, i64 0
%41 = load i32*, i32** %6
%42 = call i32 @fputs(i8* %40, i32* %41)
br label %43
43: ; preds = %39, %37
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0))
br label %47
47: ; preds = %43, %19
ret i32 0
}

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 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.4 = [4 x i8] c"%ld\00"
@.str.5 = [46 x i8] c"<P>Error in invocation - wrong FORM probably.\00"
@stdin = global i32 0
@.str.6 = [17 x i8] c"../data/data.txt\00"
@.str.7 = [2 x i8] c"a\00"
@.str.8 = [34 x i8] c"<P>Sorry, cannot store your data.\00"
@.str.9 = [49 x i8] c"<P>Thank you! Your contribution has been stored.\00"
@str = [24 x i8] c"<TITLE>Response</TITLE>\00"
define i32 @main() {
%1 = alloca [87 x i8]
%2 = alloca [87 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [87 x i8], [87 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [87 x i8], [87 x i8]* %2, i64 0, i64 0
%6 = bitcast i64* %3 to i8*
%7 = 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)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %33, label %11
11: ; preds = %0
%12 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %3)
%13 = icmp ne i32 %12, 1
%14 = load i64, i64* %3
%15 = icmp sgt i64 %14, 80
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %33, label %17
17: ; preds = %11
%18 = add nsw i64 %14, 1
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %4, i64 %18, i32 %19)
%21 = getelementptr inbounds [87 x i8], [87 x i8]* %1, i64 0, i64 5
%22 = load i64, i64* %3
%23 = getelementptr inbounds [87 x i8], [87 x i8]* %1, i64 0, i64 %22
%24 = call i32 @unencode(i8* %21, i8* %23, i8* %5)
%25 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
br label %31
29: ; preds = %17
%30 = call i32 @fputs(i8* %5, i32* %25)
br label %31
31: ; preds = %29, %27
%32 = call i32 @fclose(i32* %25)
br label %33
33: ; preds = %0, %11, %31
%34 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), %31 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), %11 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), %0 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %34)
ret i32 0
}