#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *h_util_str_join(const char *s1, const char *s2) {
  int len1, len2;
  if (s1 == NULL)
    len1 = 0;
  else
    len1 = strlen(s1);
  if (s2 == NULL)
    len2 = 0;
  else
    len2 = strlen(s2);
  int len = len1 + len2 + 1;
  char *str = malloc(len);
  memcpy(str, s1, len1);
  memcpy(str + len1, s2, len2);
  str[len - 1] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<h_util_str_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <h_util_str_join+0x27>
movl   $0x0,-0x14(%rbp)
jmp    1163 <h_util_str_join+0x33>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <h_util_str_join+0x4a>
movl   $0x0,-0x18(%rbp)
jmp    1186 <h_util_str_join+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h_util_str_join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r12d,%r12d
mov    $0x0,%r13d
test   %rdi,%rdi
je     115a <h_util_str_join+0x2a>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
test   %r14,%r14
je     116a <h_util_str_join+0x3a>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r13,1),%ebp
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
movslq %r13d,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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