#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(int /*<<< orphan*/ *);
char getchar();
int /*<<< orphan*/ *getenv(char *);
scalar_t__ malloc(int);
char *init_param() {
  char *buffer = NULL;
  int i = 0;
  int param_length = 0;
  if (getenv("CONTENT_LENGTH") == NULL)
    return NULL;
  else
    param_length = atoi(getenv("CONTENT_LENGTH"));
  buffer = (char *)malloc(param_length + 1);
  if (buffer != NULL) {
    while (i < param_length) {
      buffer[i] = getchar();
      if (buffer[i] == '+')
        buffer[i] = ' ';
      i++;
    }
    buffer[i] = '\0';
  }
  return buffer;
}


x86 assembly (clang, -O0):
<init_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1181 <init_param+0x41>
movq   $0x0,-0x8(%rbp)
jmp    121a <init_param+0xda>
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1212 <init_param+0xd2>
jmp    11b7 <init_param+0x77>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1206 <init_param+0xc6>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    11f8 <init_param+0xb8>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b7 <init_param+0x77>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_param>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11af <init_param+0x6f>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11bb <init_param+0x7b>
test   %r14d,%r14d
jle    11b4 <init_param+0x74>
mov    %r14d,%ebx
mov    $0x20,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x2b,%al
movzbl %al,%eax
cmove  %r14d,%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1190 <init_param+0x50>
jmp    11b6 <init_param+0x76>
xor    %r15d,%r15d
jmp    11bb <init_param+0x7b>
xor    %ebx,%ebx
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"CONTENT_LENGTH\00"
define i8* @init_param() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* null, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i8* null, i8** %1
br label %51
8: ; preds = %0
%9 = call i32* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @atoi(i32* %9)
store i32 %10, i32* %4
br label %11
11: ; preds = %8
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %49
18: ; preds = %11
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = call signext i8 (...) @getchar()
%25 = load i8*, i8** %2
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 43
br i1 %35, label %36, label %41
36: ; preds = %23
%37 = load i8*, i8** %2
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 32, i8* %40
br label %41
41: ; preds = %36, %23
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %19
44: ; preds = %19
%45 = load i8*, i8** %2
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %44, %11
%50 = load i8*, i8** %2
store i8* %50, i8** %1
br label %51
51: ; preds = %49, %7
%52 = load i8*, i8** %1
ret i8* %52
}

LLVM IR (-O2):
@.str = [15 x i8] c"CONTENT_LENGTH\00"
define i8* @init_param() {
%1 = tail call i32* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %26, label %3
3: ; preds = %0
%4 = tail call i32 @atoi(i32* %1)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %26, label %9
9: ; preds = %3
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %23
11: ; preds = %9
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = tail call signext i8 (...) @getchar()
%16 = getelementptr inbounds i8, i8* %7, i64 %14
%17 = icmp eq i8 %15, 43
%18 = select i1 %17, i8 32, i8 %15
store i8 %18, i8* %16
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = zext i32 %4 to i64
br label %23
23: ; preds = %9, %21
%24 = phi i64 [ %22, %21 ], [ 0, %9 ]
%25 = getelementptr inbounds i8, i8* %7, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %3, %23, %0
%27 = phi i8* [ null, %0 ], [ %7, %23 ], [ %7, %3 ]
ret i8* %27
}