#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 */
struct sr_strbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *sr_json_escape(char const *);
int /*<<< orphan*/ sr_strbuf_append_char(struct sr_strbuf *, char);
int /*<<< orphan*/ sr_strbuf_append_str(struct sr_strbuf *, char *);
struct sr_strbuf *sr_json_append_escaped(struct sr_strbuf *strbuf,
                                         const char *str) {
  char *escaped_str = sr_json_escape(str);
  sr_strbuf_append_char(strbuf, '\"');
  sr_strbuf_append_str(strbuf, escaped_str);
  sr_strbuf_append_char(strbuf, '\"');
  free(escaped_str);
  return strbuf;
}


x86 assembly (clang, -O0):
<sr_json_append_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sr_json_escape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1060 <sr_strbuf_append_char@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <sr_strbuf_append_str@plt>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1060 <sr_strbuf_append_char@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_json_append_escaped>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <sr_json_escape@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x22,%esi
call   1060 <sr_strbuf_append_char@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sr_strbuf_append_str@plt>
mov    %rbx,%rdi
mov    $0x22,%esi
call   1060 <sr_strbuf_append_char@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sr_strbuf = type { i32 }
define %struct.sr_strbuf* @sr_json_append_escaped(%struct.sr_strbuf* %0, i8* %1) {
%3 = alloca %struct.sr_strbuf*
%4 = alloca i8*
%5 = alloca i8*
store %struct.sr_strbuf* %0, %struct.sr_strbuf** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @sr_json_escape(i8* %6)
store i8* %7, i8** %5
%8 = load %struct.sr_strbuf*, %struct.sr_strbuf** %3
%9 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %8, i8 signext 34)
%10 = load %struct.sr_strbuf*, %struct.sr_strbuf** %3
%11 = load i8*, i8** %5
%12 = call i32 @sr_strbuf_append_str(%struct.sr_strbuf* %10, i8* %11)
%13 = load %struct.sr_strbuf*, %struct.sr_strbuf** %3
%14 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %13, i8 signext 34)
%15 = load i8*, i8** %5
%16 = call i32 @free(i8* %15)
%17 = load %struct.sr_strbuf*, %struct.sr_strbuf** %3
ret %struct.sr_strbuf* %17
}

LLVM IR (-O2):
%struct.sr_strbuf = type { i32 }
define %struct.sr_strbuf* @sr_json_append_escaped(%struct.sr_strbuf* returned %0, i8* %1) {
%3 = tail call i8* @sr_json_escape(i8* %1)
%4 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %0, i8 signext 34)
%5 = tail call i32 @sr_strbuf_append_str(%struct.sr_strbuf* %0, i8* %3)
%6 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %0, i8 signext 34)
%7 = tail call i32 @free(i8* %3)
ret %struct.sr_strbuf* %0
}