#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 */
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *append(char *one, char *two) {
  char *temp = malloc(sizeof(char) * (strlen(one) + 1 + strlen(two)));
  if (temp == NULL)
    return "ERROR IN MALLOC";
  strcpy(temp, one);
  strcat(temp, two);
  return temp;
}


x86 assembly (clang, -O0):
<append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119b <append+0x5b>
lea    0xe6e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <append+0x7d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1185 <append+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    118c <append+0x4c>
lea    0xe74(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ERROR IN MALLOC\00"
define i8* @append(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = sext i32 %12 to i64
%14 = mul i64 1, %13
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %3
br label %28
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %6
store i8* %27, i8** %3
br label %28
28: ; preds = %20, %19
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [16 x i8] c"ERROR IN MALLOC\00"
define i8* @append(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %4, %5
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* %7, i8* %0)
%11 = tail call i32 @strcat(i8* %7, i8* %1)
br label %12
12: ; preds = %2, %9
%13 = phi i8* [ %7, %9 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %13
}