#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 rmsummary {
  int dummy;
};
struct jx {
  int dummy;
};
struct buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buffer_putfstring(struct buffer *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ jx_delete(struct jx *);
char *jx_print_string(struct jx *);
struct jx *rmsummary_to_json(struct rmsummary const *, int);
void rmsummary_print_buffer(struct buffer *B, const struct rmsummary *s,
                            int only_resources) {
  if (!s)
    return;
  struct jx *jsum = rmsummary_to_json(s, only_resources);
  if (jsum) {
    char *str = jx_print_string(jsum);
    buffer_putfstring(B, "%s", str);
    jx_delete(jsum);
    free(str);
  }
}


x86 assembly (clang, -O0):
<rmsummary_print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <rmsummary_print_buffer+0x23>
jmp    11c1 <rmsummary_print_buffer+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <rmsummary_to_json@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c1 <rmsummary_print_buffer+0x71>
mov    -0x20(%rbp),%rdi
call   1040 <jx_print_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1060 <buffer_putfstring@plt>
mov    -0x20(%rbp),%rdi
call   1070 <jx_delete@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmsummary_print_buffer>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11a1 <rmsummary_print_buffer+0x51>
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <rmsummary_to_json@plt>
test   %rax,%rax
je     11a1 <rmsummary_print_buffer+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <jx_print_string@plt>
mov    %rax,%r15
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1060 <buffer_putfstring@plt>
mov    %rbx,%rdi
call   1070 <jx_delete@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
%struct.rmsummary = type { i32 }
%struct.jx = type { i32 }
@.str = [3 x i8] c"%s\00"
define void @rmsummary_print_buffer(%struct.buffer* %0, %struct.rmsummary* %1, i32 %2) {
%4 = alloca %struct.buffer*
%5 = alloca %struct.rmsummary*
%6 = alloca i32
%7 = alloca %struct.jx*
%8 = alloca i8*
store %struct.buffer* %0, %struct.buffer** %4
store %struct.rmsummary* %1, %struct.rmsummary** %5
store i32 %2, i32* %6
%9 = load %struct.rmsummary*, %struct.rmsummary** %5
%10 = icmp ne %struct.rmsummary* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
br label %28
12: ; preds = %3
%13 = load %struct.rmsummary*, %struct.rmsummary** %5
%14 = load i32, i32* %6
%15 = call %struct.jx* @rmsummary_to_json(%struct.rmsummary* %13, i32 %14)
store %struct.jx* %15, %struct.jx** %7
%16 = load %struct.jx*, %struct.jx** %7
%17 = icmp ne %struct.jx* %16, null
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load %struct.jx*, %struct.jx** %7
%20 = call i8* @jx_print_string(%struct.jx* %19)
store i8* %20, i8** %8
%21 = load %struct.buffer*, %struct.buffer** %4
%22 = load i8*, i8** %8
%23 = call i32 @buffer_putfstring(%struct.buffer* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load %struct.jx*, %struct.jx** %7
%25 = call i32 @jx_delete(%struct.jx* %24)
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %11, %18, %12
ret void
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
%struct.rmsummary = type { i32 }
%struct.jx = type { i32 }
@.str = [3 x i8] c"%s\00"
define void @rmsummary_print_buffer(%struct.buffer* %0, %struct.rmsummary* %1, i32 %2) {
%4 = icmp eq %struct.rmsummary* %1, null
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call %struct.jx* @rmsummary_to_json(%struct.rmsummary* %1, i32 %2)
%7 = icmp eq %struct.jx* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i8* @jx_print_string(%struct.jx* %6)
%10 = tail call i32 @buffer_putfstring(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @jx_delete(%struct.jx* %6)
%12 = tail call i32 @free(i8* %9)
br label %13
13: ; preds = %5, %8, %3
ret void
}