#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 string {
  int dummy;
};

/* Variables and functions */
struct string *alloc_str();
int /*<<< orphan*/ assert_string_equals(char *, int, struct string *);
int /*<<< orphan*/ free_str(struct string *);
int /*<<< orphan*/ str_append(struct string *, char *, char *);
void test_should_append_formatted_string_to_value(void) {
  struct string *str = alloc_str();
  str_append(str, "%s, ", "Hello");
  assert_string_equals("Hello, ", 7, str);
  str_append(str, "%s!", "World");
  assert_string_equals("Hello, World!", 13, str);
  free_str(str);
}


x86 assembly (clang, -O0):
<test_should_append_formatted_string_to_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <alloc_str@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
lea    0xea0(%rip),%rdx
call   1060 <str_append@plt>
mov    -0x8(%rbp),%rdx
lea    0xe96(%rip),%rdi
mov    $0x7,%esi
call   1040 <assert_string_equals@plt>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    0xe86(%rip),%rdx
call   1060 <str_append@plt>
mov    -0x8(%rbp),%rdx
lea    0xe7c(%rip),%rdi
mov    $0xd,%esi
call   1040 <assert_string_equals@plt>
mov    -0x8(%rbp),%rdi
call   1050 <free_str@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_should_append_formatted_string_to_value>:
push   %rbx
xor    %eax,%eax
call   1030 <alloc_str@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rsi
lea    0xeac(%rip),%rdx
mov    %rax,%rdi
call   1060 <str_append@plt>
lea    0xea3(%rip),%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1040 <assert_string_equals@plt>
lea    0xe97(%rip),%rsi
lea    0xe94(%rip),%rdx
mov    %rbx,%rdi
call   1060 <str_append@plt>
lea    0xe8b(%rip),%rdi
mov    $0xd,%esi
mov    %rbx,%rdx
call   1040 <assert_string_equals@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <free_str@plt>

LLVM IR (-O0):
%struct.string = type { i32 }
@.str = [5 x i8] c"%s, \00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [8 x i8] c"Hello, \00"
@.str.3 = [4 x i8] c"%s!\00"
@.str.4 = [6 x i8] c"World\00"
@.str.5 = [14 x i8] c"Hello, World!\00"
define void @test_should_append_formatted_string_to_value() {
%1 = alloca %struct.string*
%2 = call %struct.string* (...) @alloc_str()
store %struct.string* %2, %struct.string** %1
%3 = load %struct.string*, %struct.string** %1
%4 = call i32 @str_append(%struct.string* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = load %struct.string*, %struct.string** %1
%6 = call i32 @assert_string_equals(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7, %struct.string* %5)
%7 = load %struct.string*, %struct.string** %1
%8 = call i32 @str_append(%struct.string* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%9 = load %struct.string*, %struct.string** %1
%10 = call i32 @assert_string_equals(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13, %struct.string* %9)
%11 = load %struct.string*, %struct.string** %1
%12 = call i32 @free_str(%struct.string* %11)
ret void
}

LLVM IR (-O2):
%struct.string = type { i32 }
@.str = [5 x i8] c"%s, \00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [8 x i8] c"Hello, \00"
@.str.3 = [4 x i8] c"%s!\00"
@.str.4 = [6 x i8] c"World\00"
@.str.5 = [14 x i8] c"Hello, World!\00"
define void @test_should_append_formatted_string_to_value() {
%1 = tail call %struct.string* (...) @alloc_str()
%2 = tail call i32 @str_append(%struct.string* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @assert_string_equals(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7, %struct.string* %1)
%4 = tail call i32 @str_append(%struct.string* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%5 = tail call i32 @assert_string_equals(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13, %struct.string* %1)
%6 = tail call i32 @free_str(%struct.string* %1)
ret void
}