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

/* Variables and functions */
int /*<<< orphan*/ collect(struct value *);
char *get_str(struct value *);
char *malloc(int);
int /*<<< orphan*/ malloc_error();
int /*<<< orphan*/ new_str(char *);
struct value *pop();
int /*<<< orphan*/ push(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void builtin_append() {
  struct value *x, *y;
  x = pop();
  y = pop();
  char *b = get_str(x);
  char *a = get_str(y);
  int lena = strlen(a);
  int lenb = strlen(b);
  char *s = malloc((lena + lenb + 1) * sizeof(char));
  if (s == NULL) {
    malloc_error();
  }
  strcpy(s, a);
  strcpy(s + lena, b);
  push(new_str(s));
  collect(x);
  collect(y);
}


x86 assembly (clang, -O0):
<builtin_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1050 <pop@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <get_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120c <builtin_append+0x7c>
mov    $0x0,%al
call   1080 <malloc_error@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1090 <new_str@plt>
mov    %eax,%edi
call   10a0 <push@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <collect@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <collect@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_append>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <pop@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <pop@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <get_str@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <get_str@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11f1 <builtin_append+0x61>
xor    %eax,%eax
call   1080 <malloc_error@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
movslq %ebx,%rax
mov    %rbp,%rdi
add    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1090 <new_str@plt>
mov    %eax,%edi
call   10a0 <push@plt>
mov    %r14,%rdi
call   10b0 <collect@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <collect@plt>

LLVM IR (-O0):
%struct.value = type { i32 }
define void @builtin_append() {
%1 = alloca %struct.value*
%2 = alloca %struct.value*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = call %struct.value* (...) @pop()
store %struct.value* %8, %struct.value** %1
%9 = call %struct.value* (...) @pop()
store %struct.value* %9, %struct.value** %2
%10 = load %struct.value*, %struct.value** %1
%11 = call i8* @get_str(%struct.value* %10)
store i8* %11, i8** %3
%12 = load %struct.value*, %struct.value** %2
%13 = call i8* @get_str(%struct.value* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %5
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = add nsw i32 %18, %19
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 1
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %0
%29 = call i32 (...) @malloc_error()
br label %30
30: ; preds = %28, %0
%31 = load i8*, i8** %7
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %7
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %3
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = load i8*, i8** %7
%41 = call i32 @new_str(i8* %40)
%42 = call i32 @push(i32 %41)
%43 = load %struct.value*, %struct.value** %1
%44 = call i32 @collect(%struct.value* %43)
%45 = load %struct.value*, %struct.value** %2
%46 = call i32 @collect(%struct.value* %45)
ret void
}

LLVM IR (-O2):
%struct.value = type { i32 }
define void @builtin_append() {
%1 = tail call %struct.value* (...) @pop()
%2 = tail call %struct.value* (...) @pop()
%3 = tail call i8* @get_str(%struct.value* %1)
%4 = tail call i8* @get_str(%struct.value* %2)
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @strlen(i8* %3)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 (...) @malloc_error()
br label %13
13: ; preds = %11, %0
%14 = tail call i32 @strcpy(i8* %9, i8* %4)
%15 = sext i32 %5 to i64
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = tail call i32 @strcpy(i8* %16, i8* %3)
%18 = tail call i32 @new_str(i8* %9)
%19 = tail call i32 @push(i32 %18)
%20 = tail call i32 @collect(%struct.value* %1)
%21 = tail call i32 @collect(%struct.value* %2)
ret void
}