#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 getChar(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
char *parseBody(int fd, int contentLength) {
  if (contentLength == 0)
    return 0;
  if (0)
    printf("Parse body starting...\n");
  char *body = (char *)malloc(contentLength + 1);
  memset(body, 0, contentLength + 1);
  int i = 0;
  while (i < contentLength)
    body[i++] = getChar(fd);
  if (0)
    printf("HTTP body=[%s]\n", body);
  return body;
}


x86 assembly (clang, -O0):
<parseBody>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1155 <parseBody+0x25>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <parseBody+0x84>
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ac <parseBody+0x7c>
mov    -0xc(%rbp),%edi
call   1030 <getChar@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    117c <parseBody+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseBody>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1188 <parseBody+0x58>
mov    %esi,%r14d
mov    %edi,%r12d
lea    0x1(%r14),%r15d
mov    %r15d,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
test   %r14d,%r14d
jle    118b <parseBody+0x5b>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1030 <getChar@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <parseBody+0x40>
jmp    118b <parseBody+0x5b>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @parseBody(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %34
11: ; preds = %2
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = call i32 @memset(i8* %16, i32 0, i32 %18)
store i32 0, i32* %7
br label %20
20: ; preds = %24, %11
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %4
%26 = call signext i8 @getChar(i32 %25)
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 %26, i8* %31
br label %20
32: ; preds = %20
%33 = load i8*, i8** %6
store i8* %33, i8** %3
br label %34
34: ; preds = %32, %10
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @parseBody(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = add nsw i32 %1, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @memset(i8* %7, i32 0, i32 %5)
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %18
10: ; preds = %4
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %15, %12 ]
%14 = tail call signext i8 @getChar(i32 %0)
%15 = add nuw nsw i64 %13, 1
%16 = getelementptr inbounds i8, i8* %7, i64 %13
store i8 %14, i8* %16
%17 = icmp eq i64 %15, %11
br i1 %17, label %18, label %12
18: ; preds = %12, %4, %2
%19 = phi i8* [ null, %2 ], [ %7, %4 ], [ %7, %12 ]
ret i8* %19
}