#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 *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strstr(char const *, char *);
char *http_parse_result(const char *lpbuf) {
  char *ptmp = NULL;
  char *response = NULL;
  ptmp = (char *)strstr(lpbuf, "HTTP/1.1");
  if (!ptmp) {
    return NULL;
  }
  if (atoi(ptmp + 9) != 200) {
    printf("result:\n%s\n", lpbuf);
    return NULL;
  }
  ptmp = (char *)strstr(lpbuf, "\r\n\r\n");
  if (!ptmp) {
    return NULL;
  }
  response = (char *)malloc(strlen(ptmp) + 1);
  strcpy(response, ptmp + 4);
  return response;
}


x86 assembly (clang, -O0):
<http_parse_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <http_parse_result+0x48>
movq   $0x0,-0x8(%rbp)
jmp    123b <http_parse_result+0xdb>
mov    -0x18(%rbp),%rdi
add    $0x9,%rdi
call   1070 <atoi@plt>
cmp    $0xc8,%eax
je     11dd <http_parse_result+0x7d>
mov    -0x10(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    123b <http_parse_result+0xdb>
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1209 <http_parse_result+0xa9>
movq   $0x0,-0x8(%rbp)
jmp    123b <http_parse_result+0xdb>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_parse_result>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe92(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d6 <http_parse_result+0x76>
add    $0x9,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
cmp    $0xc8,%eax
jne    11c7 <http_parse_result+0x67>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d6 <http_parse_result+0x76>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
add    $0x4,%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11d8 <http_parse_result+0x78>
lea    0xe3b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"HTTP/1.1\00"
@.str.1 = [12 x i8] c"result:\0A%s\0A\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http_parse_result(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %38
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 9
%15 = call i32 @atoi(i8* %14)
%16 = icmp ne i32 %15, 200
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i8* null, i8** %2
br label %38
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = call i64 @strstr(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %20
store i8* null, i8** %2
br label %38
27: ; preds = %20
%28 = load i8*, i8** %4
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %29, 1
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 4
%36 = call i32 @strcpy(i8* %33, i8* %35)
%37 = load i8*, i8** %5
store i8* %37, i8** %2
br label %38
38: ; preds = %27, %26, %17, %11
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [9 x i8] c"HTTP/1.1\00"
@.str.1 = [12 x i8] c"result:\0A%s\0A\00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http_parse_result(i8* %0) {
%2 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = inttoptr i64 %2 to i8*
%6 = getelementptr inbounds i8, i8* %5, i64 9
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %7, 200
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
11: ; preds = %4
%12 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = tail call i64 @strlen(i8* %13)
%17 = add nsw i64 %16, 1
%18 = tail call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %13, i64 4
%21 = tail call i32 @strcpy(i8* %19, i8* %20)
br label %22
22: ; preds = %11, %1, %15, %9
%23 = phi i8* [ null, %9 ], [ %19, %15 ], [ null, %1 ], [ null, %11 ]
ret i8* %23
}