#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 /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *get_json_response(char *token_h, char *res_body) {
  char *json_res = malloc(1024);
  bzero(json_res, 1024);
  strcpy(json_res, "{\"tokenHeader\":\"");
  strcat(json_res, token_h);
  strcat(json_res, "\",\"responseBody\":\"");
  char *tmp_body = malloc(512);
  int i = 0;
  int o = 0;
  while ((res_body + i)[0] != '\0') {
    if ((res_body + i)[0] == '\"' && (res_body + (i - 1))[0] != '\\') {
      (tmp_body + o)[0] = '\\';
      ++o;
      (tmp_body + o)[0] = '"';
    } else {
      memcpy(tmp_body + o, (res_body + i), 1);
    }
    ++i;
    ++o;
  }
  strcat(json_res, tmp_body);
  free(tmp_body);
  strcat(json_res, "\"}");
  json_res = realloc(json_res, strlen(json_res) + 1);
  return json_res;
}


x86 assembly (clang, -O0):
<get_json_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1090 <bzero@plt>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   10a0 <strcat@plt>
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1296 <get_json_response+0x116>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    125f <get_json_response+0xdf>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     125f <get_json_response+0xdf>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x22,(%rax,%rcx,1)
jmp    127f <get_json_response+0xff>
mov    -0x20(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1060 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f5 <get_json_response+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_json_response>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x400,%esi
call   1090 <bzero@plt>
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
jmp    1204 <get_json_response+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebx,%rbx
movw   $0x225c,(%r15,%rbx,1)
add    $0x1,%ebx
add    $0x1,%ebx
add    $0x1,%r12
movzbl (%r12),%eax
cmp    $0x22,%al
je     1220 <get_json_response+0xa0>
test   %al,%al
jne    1228 <get_json_response+0xa8>
jmp    123d <get_json_response+0xbd>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x5c,-0x1(%r12)
jne    11f0 <get_json_response+0x70>
movslq %ebx,%rdi
add    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <memcpy@plt>
jmp    11fd <get_json_response+0x7d>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xdcd(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <realloc@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"{\22tokenHeader\22:\22\00"
@.str.1 = [19 x i8] c"\22,\22responseBody\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
define i8* @get_json_response(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i8* @malloc(i32 1024)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @bzero(i8* %10, i32 1024)
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = call i32 @strcat(i8* %14, i8* %15)
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = call i8* @malloc(i32 512)
store i8* %19, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %20
20: ; preds = %71, %2
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %76
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 34
br i1 %37, label %38, label %61
38: ; preds = %29
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 92
br i1 %47, label %48, label %61
48: ; preds = %38
%49 = load i8*, i8** %6
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 0
store i8 92, i8* %53
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = load i8*, i8** %6
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 0
store i8 34, i8* %60
br label %71
61: ; preds = %38, %29
%62 = load i8*, i8** %6
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8*, i8** %4
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = call i32 @memcpy(i8* %65, i8* %69, i32 1)
br label %71
71: ; preds = %61, %48
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %20
76: ; preds = %20
%77 = load i8*, i8** %5
%78 = load i8*, i8** %6
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = load i8*, i8** %6
%81 = call i32 @free(i8* %80)
%82 = load i8*, i8** %5
%83 = call i32 @strcat(i8* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%84 = load i8*, i8** %5
%85 = load i8*, i8** %5
%86 = call i64 @strlen(i8* %85)
%87 = add nsw i64 %86, 1
%88 = call i8* @realloc(i8* %84, i64 %87)
store i8* %88, i8** %5
%89 = load i8*, i8** %5
ret i8* %89
}

LLVM IR (-O2):
@.str = [17 x i8] c"{\22tokenHeader\22:\22\00"
@.str.1 = [19 x i8] c"\22,\22responseBody\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
define noalias i8* @get_json_response(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i32 @bzero(i8* %3, i32 1024)
%5 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strcat(i8* %3, i8* %0)
%7 = tail call i32 @strcat(i8* %3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
br label %9
9: ; preds = %29, %2
%10 = phi i64 [ %31, %29 ], [ 0, %2 ]
%11 = phi i32 [ %32, %29 ], [ 0, %2 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
switch i8 %13, label %25 [
i8 0, label %33
i8 34, label %14
]
14: ; preds = %9
%15 = add nsw i64 %10, -1
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 92
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = sext i32 %11 to i64
%21 = getelementptr inbounds i8, i8* %8, i64 %20
store i8 92, i8* %21
%22 = add nsw i32 %11, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %8, i64 %23
store i8 34, i8* %24
br label %29
25: ; preds = %9, %14
%26 = sext i32 %11 to i64
%27 = getelementptr inbounds i8, i8* %8, i64 %26
%28 = tail call i32 @memcpy(i8* %27, i8* %12, i32 1)
br label %29
29: ; preds = %25, %19
%30 = phi i32 [ %22, %19 ], [ %11, %25 ]
%31 = add nuw i64 %10, 1
%32 = add nsw i32 %30, 1
br label %9
33: ; preds = %9
%34 = tail call i32 @strcat(i8* %3, i8* %8)
%35 = tail call i32 @free(i8* %8)
%36 = tail call i32 @strcat(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%38 = add nsw i64 %37, 1
%39 = tail call i8* @realloc(i8* %3, i64 %38)
ret i8* %39
}