#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 */
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ wFree(char *);
scalar_t__ wMalloc(int);
char *wPopString();
int /*<<< orphan*/ wPushString(char *);
void wBasConcat() {
  int len1, len2;
  char *string1, *string2, *buffer;
  string2 = wPopString();
  string1 = wPopString();
  len1 = strlen(string1), len2 = strlen(string2);
  buffer = (char *)wMalloc(len1 + len2 + 1);
  memcpy(buffer, string1, len1);
  memcpy(buffer + len1, string2, len2);
  buffer[len1 + len2] = '\0';
  wPushString(buffer);
  wFree(string1);
  wFree(string2);
}


x86 assembly (clang, -O0):
<wBasConcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <wPopString@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <wPopString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
add    -0x8(%rbp),%edi
add    $0x1,%edi
call   1060 <wMalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x4(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1070 <wPushString@plt>
mov    -0x10(%rbp),%rdi
call   1080 <wFree@plt>
mov    -0x18(%rbp),%rdi
call   1080 <wFree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wBasConcat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <wPopString@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <wPopString@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r13,1),%ebp
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1060 <wMalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
movslq %r13d,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1070 <wPushString@plt>
mov    %r15,%rdi
call   1080 <wFree@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <wFree@plt>

LLVM IR (-O0):
define void @wBasConcat() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i8* (...) @wPopString()
store i8* %6, i8** %4
%7 = call i8* (...) @wPopString()
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %1
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %2
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = add nsw i32 %12, %13
%15 = add nsw i32 %14, 1
%16 = call i64 @wMalloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = load i32, i32* %1
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i8*, i8** %5
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8*, i8** %4
%27 = load i32, i32* %2
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
%29 = load i8*, i8** %5
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = add nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %5
%36 = call i32 @wPushString(i8* %35)
%37 = load i8*, i8** %3
%38 = call i32 @wFree(i8* %37)
%39 = load i8*, i8** %4
%40 = call i32 @wFree(i8* %39)
ret void
}

LLVM IR (-O2):
define void @wBasConcat() {
%1 = tail call i8* (...) @wPopString()
%2 = tail call i8* (...) @wPopString()
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = add nsw i32 %5, 1
%7 = tail call i64 @wMalloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @memcpy(i8* %8, i8* %2, i32 %3)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %1, i32 %4)
%13 = sext i32 %5 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %14
%15 = tail call i32 @wPushString(i8* %8)
%16 = tail call i32 @wFree(i8* %2)
%17 = tail call i32 @wFree(i8* %1)
ret void
}