#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, unsigned int);
void write_native_message(char *key, char *val) {
  char *json_pre_key = "{\"";
  char *json_post_key = "\":\"";
  char *json_end = "\"}";
  size_t msg_length = ((sizeof(char)) * (strlen(json_pre_key) + strlen(key) +
                                         strlen(json_post_key) + strlen(val) +
                                         strlen(json_end))) +
                      (sizeof(char));
  char *msg = malloc(msg_length);
  strcpy(msg, json_pre_key);
  strcat(msg, key);
  strcat(msg, json_post_key);
  strcat(msg, val);
  strcat(msg, json_end);
  msg[msg_length - 1] = '\0';
  unsigned int outLen = strlen(msg);
  char *bOutLen = (char *)&outLen;
  write(1, bOutLen, 4);
  write(1, msg, outLen);
  fflush(stdout);
  free(msg);
}


x86 assembly (clang, -O0):
<write_native_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe71(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x3c(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1050 <write@plt>
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    $0x1,%edi
call   1050 <write@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_native_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe78(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
add    %ebx,%ebp
lea    0xe61(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
add    %ebx,%r12d
lea    0xe47(%rip),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
add    %r12d,%eax
movslq %eax,%rbp
lea    0x1(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xe1c(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
lea    0xe05(%rip),%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1050 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"{\22\00"
@.str.1 = [4 x i8] c"\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
@stdout = global i32 0
define void @write_native_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = load i8*, i8** %7
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %22, %24
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = add i64 %27, 1
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8*, i8** %5
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %9
%35 = load i8*, i8** %3
%36 = call i32 @strcat(i8* %34, i8* %35)
%37 = load i8*, i8** %9
%38 = load i8*, i8** %6
%39 = call i32 @strcat(i8* %37, i8* %38)
%40 = load i8*, i8** %9
%41 = load i8*, i8** %4
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %9
%44 = load i8*, i8** %7
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i8*, i8** %9
%47 = load i64, i64* %8
%48 = sub i64 %47, 1
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %9
%51 = call i32 @strlen(i8* %50)
store i32 %51, i32* %10
%52 = bitcast i32* %10 to i8*
store i8* %52, i8** %11
%53 = load i8*, i8** %11
%54 = call i32 @write(i32 1, i8* %53, i32 4)
%55 = load i8*, i8** %9
%56 = load i32, i32* %10
%57 = call i32 @write(i32 1, i8* %55, i32 %56)
%58 = load i32, i32* @stdout
%59 = call i32 @fflush(i32 %58)
%60 = load i8*, i8** %9
%61 = call i32 @free(i8* %60)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"{\22\00"
@.str.1 = [4 x i8] c"\22:\22\00"
@.str.2 = [3 x i8] c"\22}\00"
@stdout = global i32 0
define void @write_native_message(i8* %0, i8* %1) {
%3 = alloca i32
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, %4
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = add nsw i32 %6, %7
%9 = tail call i32 @strlen(i8* %1)
%10 = add nsw i32 %8, %9
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = add nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, 1
%15 = tail call i8* @malloc(i64 %14)
%16 = tail call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @strcat(i8* %15, i8* %0)
%18 = tail call i32 @strcat(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @strcat(i8* %15, i8* %1)
%20 = tail call i32 @strcat(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds i8, i8* %15, i64 %13
store i8 0, i8* %21
%22 = bitcast i32* %3 to i8*
%23 = tail call i32 @strlen(i8* %15)
store i32 %23, i32* %3
%24 = call i32 @write(i32 1, i8* %22, i32 4)
%25 = tail call i32 @write(i32 1, i8* %15, i32 %23)
%26 = load i32, i32* @stdout
%27 = tail call i32 @fflush(i32 %26)
%28 = tail call i32 @free(i8* %15)
ret void
}