#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(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
void printf_post_request(char *post, char *head) {
  if (post) {
    char *content_length = strstr(head, "Content-Length: ");
    if (content_length) {
      char *br_content_length = strstr(content_length, "\r\n");
      if (br_content_length > content_length) {
        int body_len = 0;
        char *request_end = strstr(br_content_length, "\r\n\r\n");
        content_length += strlen("Content-Length: ");
        br_content_length[0] = '\0';
        body_len = atoi(content_length);
        if (request_end) {
          char *body = request_end + 4;
          int i = 0;
          printf("body_len:%d\n", body_len);
          for (i = 0; i < body_len; ++i) {
            if (body[i] == '&') {
              putchar('\n');
            } else {
              putchar(body[i]);
            }
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<printf_post_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1292 <printf_post_request+0x142>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     128d <printf_post_request+0x13d>
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1288 <printf_post_request+0x138>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
lea    0xe32(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1283 <printf_post_request+0x133>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdf8(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    127e <printf_post_request+0x12e>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x26,%eax
jne    125a <printf_post_request+0x10a>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    126b <printf_post_request+0x11b>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    1270 <printf_post_request+0x120>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122a <printf_post_request+0xda>
jmp    1283 <printf_post_request+0x133>
jmp    1288 <printf_post_request+0x138>
jmp    128d <printf_post_request+0x13d>
jmp    1292 <printf_post_request+0x142>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_post_request>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     120c <printf_post_request+0xbc>
lea    0xe99(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     120c <printf_post_request+0xbc>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1070 <strstr@plt>
cmp    %rbx,%rax
jbe    120c <printf_post_request+0xbc>
mov    %rax,%r15
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
call   1070 <strstr@plt>
mov    %rax,%r14
lea    0xe52(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
movb   $0x0,(%r15)
mov    %rbx,%rdi
call   1060 <atoi@plt>
test   %r14,%r14
je     120c <printf_post_request+0xbc>
mov    %eax,%ebx
lea    0xe44(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebx,%ebx
jle    120c <printf_post_request+0xbc>
mov    %ebx,%r15d
xor    %ebx,%ebx
mov    $0xa,%ebp
nopw   0x0(%rax,%rax,1)
movzbl 0x4(%r14,%rbx,1),%eax
cmp    $0x26,%al
cmove  %ebp,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11f0 <printf_post_request+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Content-Length: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.3 = [13 x i8] c"body_len:%d\0A\00"
define void @printf_post_request(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %71
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %70
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = icmp ugt i8* %21, %22
br i1 %23, label %24, label %69
24: ; preds = %18
store i32 0, i32* %7
%25 = load i8*, i8** %6
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %8
%27 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %5
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8* %30, i8** %5
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 0, i8* %32
%33 = load i8*, i8** %5
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i8*, i8** %8
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %68
37: ; preds = %24
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 4
store i8* %39, i8** %9
store i32 0, i32* %10
%40 = load i32, i32* %7
%41 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %40)
store i32 0, i32* %10
br label %42
42: ; preds = %64, %37
%43 = load i32, i32* %10
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %67
46: ; preds = %42
%47 = load i8*, i8** %9
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 38
br i1 %53, label %54, label %56
54: ; preds = %46
%55 = call i32 @putchar(i8 signext 10)
br label %63
56: ; preds = %46
%57 = load i8*, i8** %9
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @putchar(i8 signext %61)
br label %63
63: ; preds = %56, %54
br label %64
64: ; preds = %63
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %42
67: ; preds = %42
br label %68
68: ; preds = %67, %24
br label %69
69: ; preds = %68, %18
br label %70
70: ; preds = %69, %13
br label %71
71: ; preds = %70, %2
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Content-Length: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.3 = [13 x i8] c"body_len:%d\0A\00"
define void @printf_post_request(i8* readnone %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %32, label %4
4: ; preds = %2
%5 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = tail call i8* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ugt i8* %8, %5
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = tail call i8* @strstr(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %5, i64 %13
store i8 0, i8* %8
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp eq i8* %11, null
br i1 %16, label %32, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %11, i64 4
%19 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%20 = icmp sgt i32 %15, 0
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = zext i32 %15 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %30, %23 ]
%25 = getelementptr inbounds i8, i8* %18, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 38
%28 = select i1 %27, i8 10, i8 %26
%29 = tail call i32 @putchar(i8 signext %28)
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %22
br i1 %31, label %32, label %23
32: ; preds = %23, %17, %4, %10, %7, %2
ret void
}