#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *concat(uint32_t *env) {
  uint32_t *context = (uint32_t *)*(uint32_t **)(env + 1);
  char *s1 = *(char **)(context);
  char *s2 = *(char **)(context + 1);
  int len = (strlen(s1) + strlen(s2) + 1);
  char *s = (char *)malloc(len * sizeof(char));
  strcpy(s, s1);
  strcpy(s + strlen(s1), s2);
  s[len - 1] = 0;
  return s;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x4(%rdi),%rax
mov    (%rax),%r15
mov    0x4(%rax),%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%ebp
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @concat(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32* %0, i32** %2
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = bitcast i32* %9 to i32**
%11 = load i32*, i32** %10
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = bitcast i32* %12 to i8**
%14 = load i8*, i8** %13
store i8* %14, i8** %4
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = bitcast i32* %16 to i8**
%18 = load i8*, i8** %17
store i8* %18, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %20, %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %7
%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 i8*, i8** %4
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8*, i8** %5
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %7
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %7
ret i8* %46
}

LLVM IR (-O2):
define i8* @concat(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 1
%3 = bitcast i32* %2 to i32**
%4 = load i32*, i32** %3
%5 = bitcast i32* %4 to i8**
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i32, i32* %4, i64 1
%8 = bitcast i32* %7 to i8**
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %6)
%11 = tail call i32 @strlen(i8* %9)
%12 = add nsw i32 %11, %10
%13 = add nsw i32 %12, 1
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @strcpy(i8* %15, i8* %6)
%17 = tail call i32 @strlen(i8* %6)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = tail call i32 @strcpy(i8* %19, i8* %9)
%21 = sext i32 %12 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
store i8 0, i8* %22
ret i8* %15
}