#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 */
scalar_t__ my_strlen(char *);
char *x_malloc(int, scalar_t__);
char *concate(char *str1, char *str2) {
  char *str3;
  int i;
  i = 0;
  str3 = x_malloc(sizeof(*str3), my_strlen(str1) + my_strlen(str2));
  while (str1) {
    str3[i] = str1[i];
    i++;
  }
  i = 0;
  while (str2) {
    str3[i] = str2[i];
    i++;
  }
  return (str3);
}


x86 assembly (clang, -O0):
<concate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x28(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edi
call   1040 <x_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1191 <concate+0x71>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <concate+0x42>
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c7 <concate+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1198 <concate+0x78>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concate>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <my_strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <my_strlen@plt>
add    %rax,%r15
mov    $0x1,%edi
mov    %r15,%rsi
call   1040 <x_malloc@plt>
test   %rbx,%rbx
je     116d <concate+0x4d>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rcx,1),%edx
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
jmp    1160 <concate+0x40>
test   %r14,%r14
je     118e <concate+0x6e>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rcx,1),%edx
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
jmp    1180 <concate+0x60>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @concate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i64 @my_strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i64 @my_strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = call i8* @x_malloc(i32 1, i64 %11)
store i8* %12, i8** %5
br label %13
13: ; preds = %16, %2
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %13
28: ; preds = %13
store i32 0, i32* %6
br label %29
29: ; preds = %32, %28
%30 = load i8*, i8** %4
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %5
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %29
44: ; preds = %29
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
define i8* @concate(i8* %0, i8* %1) {
%3 = tail call i64 @my_strlen(i8* %0)
%4 = tail call i64 @my_strlen(i8* %1)
%5 = add nsw i64 %4, %3
%6 = tail call i8* @x_malloc(i32 1, i64 %5)
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = icmp eq i8* %1, null
br i1 %9, label %22, label %16
10: ; preds = %2, %10
%11 = phi i64 [ %15, %10 ], [ 0, %2 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %6, i64 %11
store i8 %13, i8* %14
%15 = add nuw i64 %11, 1
br label %10
16: ; preds = %8, %16
%17 = phi i64 [ %21, %16 ], [ 0, %8 ]
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %6, i64 %17
store i8 %19, i8* %20
%21 = add nuw i64 %17, 1
br label %16
22: ; preds = %8
ret i8* %6
}