#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 */
scalar_t__ http_recv_line(int, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, ...);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strstr(char *, char *);
int getResponseAndPost(int fd, char *jsonBuf, int jBufLen) {
  int iret = 0;
  char buff[512];
  int status = 0;
  int jLen = 0, jRLen;
  char header_n[256];
  char header_p[256];
  memset(buff, 0, 512);
  if (http_recv_line(fd, buff, 512) < 0) {
    iret = -1;
    goto end;
  }
  if (!strstr(buff, "POST")) {
    sscanf(buff, "%*s%d", &status);
    if (status != 200) {
      iret = -1;
      goto end;
    }
  }
  while (strcmp(buff, "\r\n") != 0) {
    memset(buff, 0, 512);
    memset(header_n, 0, 256);
    memset(header_p, 0, 256);
    if (http_recv_line(fd, buff, 512) < 0) {
      iret = -1;
      goto end;
    }
    sscanf(buff, "%255s%255s", header_n, header_p);
    if (strncmp(header_n, "Content-Length:", 255) == 0) {
      sscanf(header_p, "%d", &jLen);
    }
  }
  if (jLen > 0 && jBufLen >= (jLen + 1)) {
    int offset = 0;
    while (offset < jLen) {
      jRLen = recv(fd, jsonBuf + offset, jLen - offset, 0);
      if (jRLen <= 0) {
        iret = -1;
        break;
      }
      offset += jRLen;
    }
    if (offset == jLen) {
      jsonBuf[jLen] = 0;
    }
  } else if (jLen)
    iret = -1;
end:
  return iret;
}


x86 assembly (clang, -O0):
<getResponseAndPost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1080 <http_recv_line@plt>
cmp    $0x0,%rax
jge    11dd <getResponseAndPost+0x6d>
movl   $0xffffffff,-0x18(%rbp)
jmp    13fc <getResponseAndPost+0x28c>
lea    -0x220(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%eax
jne    1236 <getResponseAndPost+0xc6>
lea    -0x220(%rbp),%rdi
lea    0xdfe(%rip),%rsi
lea    -0x224(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmpl   $0xc8,-0x224(%rbp)
je     1231 <getResponseAndPost+0xc1>
movl   $0xffffffff,-0x18(%rbp)
jmp    13fc <getResponseAndPost+0x28c>
jmp    1236 <getResponseAndPost+0xc6>
jmp    123b <getResponseAndPost+0xcb>
lea    -0x220(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1321 <getResponseAndPost+0x1b1>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1080 <http_recv_line@plt>
cmp    $0x0,%rax
jge    12bb <getResponseAndPost+0x14b>
movl   $0xffffffff,-0x18(%rbp)
jmp    13fc <getResponseAndPost+0x28c>
lea    -0x220(%rbp),%rdi
lea    -0x330(%rbp),%rdx
lea    -0x430(%rbp),%rcx
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1070 <sscanf@plt>
lea    -0x330(%rbp),%rdi
lea    0xd2d(%rip),%rsi
mov    $0xff,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    131c <getResponseAndPost+0x1ac>
lea    -0x430(%rbp),%rdi
lea    0xcfa(%rip),%rsi
lea    -0x228(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
jmp    123b <getResponseAndPost+0xcb>
cmpl   $0x0,-0x228(%rbp)
jle    13de <getResponseAndPost+0x26e>
mov    -0x14(%rbp),%eax
mov    -0x228(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jl     13de <getResponseAndPost+0x26e>
movl   $0x0,-0x434(%rbp)
mov    -0x434(%rbp),%eax
cmp    -0x228(%rbp),%eax
jge    13b8 <getResponseAndPost+0x248>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x434(%rbp),%rax
add    %rax,%rsi
mov    -0x228(%rbp),%edx
sub    -0x434(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0x0,-0x22c(%rbp)
jg     13a1 <getResponseAndPost+0x231>
movl   $0xffffffff,-0x18(%rbp)
jmp    13b8 <getResponseAndPost+0x248>
mov    -0x22c(%rbp),%eax
add    -0x434(%rbp),%eax
mov    %eax,-0x434(%rbp)
jmp    134c <getResponseAndPost+0x1dc>
mov    -0x434(%rbp),%eax
cmp    -0x228(%rbp),%eax
jne    13d9 <getResponseAndPost+0x269>
mov    -0x10(%rbp),%rax
movslq -0x228(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    13f7 <getResponseAndPost+0x287>
cmpl   $0x0,-0x228(%rbp)
je     13f2 <getResponseAndPost+0x282>
movl   $0xffffffff,-0x18(%rbp)
jmp    13f7 <getResponseAndPost+0x287>
jmp    13fc <getResponseAndPost+0x28c>
mov    -0x18(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getResponseAndPost>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%r13d
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1080 <http_recv_line@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     1356 <getResponseAndPost+0x1e6>
lea    0xe2d(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1090 <strstr@plt>
test   %eax,%eax
jne    1207 <getResponseAndPost+0x97>
lea    0xe1d(%rip),%rsi
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
cmpl   $0xc8,0x10(%rsp)
jne    1356 <getResponseAndPost+0x1e6>
lea    0xdfd(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12f1 <getResponseAndPost+0x181>
mov    %r15d,0x14(%rsp)
mov    %r14,0x18(%rsp)
lea    0x20(%rsp),%rbx
lea    0x320(%rsp),%rbp
lea    0x220(%rsp),%r15
lea    0xdd2(%rip),%r12
lea    0xdbd(%rip),%r14
jmp    1264 <getResponseAndPost+0xf4>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1300 <getResponseAndPost+0x190>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1080 <http_recv_line@plt>
test   %rax,%rax
js     12f9 <getResponseAndPost+0x189>
mov    %rbx,%rdi
lea    0xd5e(%rip),%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0xff,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1250 <getResponseAndPost+0xe0>
mov    %r15,%rdi
lea    0xd28(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
jmp    1250 <getResponseAndPost+0xe0>
xor    %edx,%edx
neg    %edx
sbb    %ebp,%ebp
jmp    1356 <getResponseAndPost+0x1e6>
mov    $0xffffffff,%ebp
jmp    1356 <getResponseAndPost+0x1e6>
mov    0xc(%rsp),%edx
test   %edx,%edx
mov    0x18(%rsp),%r14
jle    12f3 <getResponseAndPost+0x183>
cmp    0x14(%rsp),%edx
jge    12f3 <getResponseAndPost+0x183>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rax
lea    (%r14,%rax,1),%rsi
sub    %eax,%edx
mov    %r13d,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0xc(%rsp),%edx
test   %eax,%eax
jle    1345 <getResponseAndPost+0x1d5>
add    %eax,%ebx
cmp    %ebx,%edx
jg     1320 <getResponseAndPost+0x1b0>
xor    %ebp,%ebp
jmp    134a <getResponseAndPost+0x1da>
mov    $0xffffffff,%ebp
cmp    %edx,%ebx
jne    1356 <getResponseAndPost+0x1e6>
movslq %edx,%rax
movb   $0x0,(%r14,%rax,1)
mov    %ebp,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"POST\00"
@.str.1 = [6 x i8] c"%*s%d\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [11 x i8] c"%255s%255s\00"
@.str.4 = [16 x i8] c"Content-Length:\00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @getResponseAndPost(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca [256 x i8]
%14 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 512)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%19 = call i64 @http_recv_line(i32 %17, i8* %18, i32 512)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %7
br label %108
22: ; preds = %3
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%24 = call i32 @strstr(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %22
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%28 = call i32 (i8*, i8*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 200
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -1, i32* %7
br label %108
32: ; preds = %26
br label %33
33: ; preds = %32, %22
br label %34
34: ; preds = %61, %33
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %62
38: ; preds = %34
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 512)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 256)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 256)
%45 = load i32, i32* %4
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%47 = call i64 @http_recv_line(i32 %45, i8* %46, i32 512)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %38
store i32 -1, i32* %7
br label %108
50: ; preds = %38
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%54 = call i32 (i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %52, i8* %53)
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 255)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%60 = call i32 (i8*, i8*, ...) @sscanf(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %10)
br label %61
61: ; preds = %58, %50
br label %34
62: ; preds = %34
%63 = load i32, i32* %10
%64 = icmp sgt i32 %63, 0
br i1 %64, label %65, label %102
65: ; preds = %62
%66 = load i32, i32* %6
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
%69 = icmp sge i32 %66, %68
br i1 %69, label %70, label %102
70: ; preds = %65
store i32 0, i32* %14
br label %71
71: ; preds = %88, %70
%72 = load i32, i32* %14
%73 = load i32, i32* %10
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %92
75: ; preds = %71
%76 = load i32, i32* %4
%77 = load i8*, i8** %5
%78 = load i32, i32* %14
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i32, i32* %10
%82 = load i32, i32* %14
%83 = sub nsw i32 %81, %82
%84 = call i32 @recv(i32 %76, i8* %80, i32 %83, i32 0)
store i32 %84, i32* %11
%85 = load i32, i32* %11
%86 = icmp sle i32 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %75
store i32 -1, i32* %7
br label %92
88: ; preds = %75
%89 = load i32, i32* %11
%90 = load i32, i32* %14
%91 = add nsw i32 %90, %89
store i32 %91, i32* %14
br label %71
92: ; preds = %87, %71
%93 = load i32, i32* %14
%94 = load i32, i32* %10
%95 = icmp eq i32 %93, %94
br i1 %95, label %96, label %101
96: ; preds = %92
%97 = load i8*, i8** %5
%98 = load i32, i32* %10
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
store i8 0, i8* %100
br label %101
101: ; preds = %96, %92
br label %107
102: ; preds = %65, %62
%103 = load i32, i32* %10
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %102
store i32 -1, i32* %7
br label %106
106: ; preds = %105, %102
br label %107
107: ; preds = %106, %101
br label %108
108: ; preds = %107, %49, %31, %21
%109 = load i32, i32* %7
ret i32 %109
}

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