#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*/ int8_t;

/* Variables and functions */
scalar_t__ calloc(int, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int8_t *ll_strcat(int8_t *s1, int8_t *s2) {
  int l1 = strlen((char *)s1);
  int l2 = strlen((char *)s2);
  char *buf = (char *)calloc(l1 + l2 + 1, sizeof(char));
  strncpy(buf, (char *)s1, l1);
  strncpy(buf + l1, (char *)s2, l2 + 1);
  return (int8_t *)buf;
}


x86 assembly (clang, -O0):
<ll_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    -0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_strcat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%r12d
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rdi
add    %rbp,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @ll_strcat(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = load i32*, i32** %3
%9 = bitcast i32* %8 to i8*
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32*, i32** %4
%12 = bitcast i32* %11 to i8*
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = add nsw i32 %14, %15
%17 = add nsw i32 %16, 1
%18 = call i64 @calloc(i32 %17, i32 1)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i32*, i32** %3
%22 = bitcast i32* %21 to i8*
%23 = load i32, i32* %5
%24 = call i32 @strncpy(i8* %20, i8* %22, i32 %23)
%25 = load i8*, i8** %7
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i32*, i32** %4
%30 = bitcast i32* %29 to i8*
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = call i32 @strncpy(i8* %28, i8* %30, i32 %32)
%34 = load i8*, i8** %7
%35 = bitcast i8* %34 to i32*
ret i32* %35
}

LLVM IR (-O2):
define i32* @ll_strcat(i32* %0, i32* %1) {
%3 = bitcast i32* %0 to i8*
%4 = tail call i32 @strlen(i8* %3)
%5 = bitcast i32* %1 to i8*
%6 = tail call i32 @strlen(i8* %5)
%7 = add i32 %6, 1
%8 = add i32 %7, %4
%9 = tail call i64 @calloc(i32 %8, i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strncpy(i8* %10, i8* %3, i32 %4)
%12 = sext i32 %4 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = tail call i32 @strncpy(i8* %13, i8* %5, i32 %7)
%15 = inttoptr i64 %9 to i32*
ret i32* %15
}