#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 getResponse(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;
  }
  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):
<getResponse>:
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    11cd <getResponse+0x6d>
movl   $0xffffffff,-0x18(%rbp)
jmp    13cb <getResponse+0x26b>
lea    -0x220(%rbp),%rdi
lea    0xe25(%rip),%rsi
lea    -0x224(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmpl   $0xc8,-0x224(%rbp)
je     1205 <getResponse+0xa5>
movl   $0xffffffff,-0x18(%rbp)
jmp    13cb <getResponse+0x26b>
jmp    120a <getResponse+0xaa>
lea    -0x220(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12f0 <getResponse+0x190>
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    128a <getResponse+0x12a>
movl   $0xffffffff,-0x18(%rbp)
jmp    13cb <getResponse+0x26b>
lea    -0x220(%rbp),%rdi
lea    -0x330(%rbp),%rdx
lea    -0x430(%rbp),%rcx
lea    0xd63(%rip),%rsi
mov    $0x0,%al
call   1070 <sscanf@plt>
lea    -0x330(%rbp),%rdi
lea    0xd59(%rip),%rsi
mov    $0xff,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12eb <getResponse+0x18b>
lea    -0x430(%rbp),%rdi
lea    0xd26(%rip),%rsi
lea    -0x228(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
jmp    120a <getResponse+0xaa>
cmpl   $0x0,-0x228(%rbp)
jle    13ad <getResponse+0x24d>
mov    -0x14(%rbp),%eax
mov    -0x228(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jl     13ad <getResponse+0x24d>
movl   $0x0,-0x434(%rbp)
mov    -0x434(%rbp),%eax
cmp    -0x228(%rbp),%eax
jge    1387 <getResponse+0x227>
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     1370 <getResponse+0x210>
movl   $0xffffffff,-0x18(%rbp)
jmp    1387 <getResponse+0x227>
mov    -0x22c(%rbp),%eax
add    -0x434(%rbp),%eax
mov    %eax,-0x434(%rbp)
jmp    131b <getResponse+0x1bb>
mov    -0x434(%rbp),%eax
cmp    -0x228(%rbp),%eax
jne    13a8 <getResponse+0x248>
mov    -0x10(%rbp),%rax
movslq -0x228(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    13c6 <getResponse+0x266>
cmpl   $0x0,-0x228(%rbp)
je     13c1 <getResponse+0x261>
movl   $0xffffffff,-0x18(%rbp)
jmp    13c6 <getResponse+0x266>
jmp    13cb <getResponse+0x26b>
mov    -0x18(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getResponse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
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,%r15d
test   %rax,%rax
js     131d <getResponse+0x1bd>
lea    0xe3c(%rip),%rsi
xor    %ebx,%ebx
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
cmpl   $0xc8,0x10(%rsp)
jne    131d <getResponse+0x1bd>
lea    0xe1a(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1318 <getResponse+0x1b8>
mov    %r14d,0x14(%rsp)
mov    %rbp,0x18(%rsp)
lea    0x20(%rsp),%rbx
lea    0x320(%rsp),%rbp
lea    0x220(%rsp),%r15
lea    0xdef(%rip),%r12
lea    0xdda(%rip),%r14
jmp    1244 <getResponse+0xe4>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12d9 <getResponse+0x179>
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     12d1 <getResponse+0x171>
mov    %rbx,%rdi
lea    0xd79(%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    1230 <getResponse+0xd0>
mov    %r15,%rdi
lea    0xd43(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
jmp    1230 <getResponse+0xd0>
mov    $0xffffffff,%r15d
jmp    131d <getResponse+0x1bd>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
mov    0x18(%rsp),%r14
jle    1318 <getResponse+0x1b8>
cmp    0x14(%rsp),%ebx
jge    1318 <getResponse+0x1b8>
xor    %ebp,%ebp
xchg   %ax,%ax
movslq %ebp,%rax
lea    (%r14,%rax,1),%rsi
sub    %eax,%ebx
mov    %r13d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0xc(%rsp),%ebx
test   %eax,%eax
jle    1332 <getResponse+0x1d2>
add    %eax,%ebp
cmp    %ebp,%ebx
jg     12f0 <getResponse+0x190>
xor    %r15d,%r15d
jmp    1338 <getResponse+0x1d8>
neg    %ebx
sbb    %r15d,%r15d
mov    %r15d,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r15d
cmp    %ebx,%ebp
jne    131d <getResponse+0x1bd>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
jmp    131d <getResponse+0x1bd>

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

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