#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__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *strdup3(const char *s1, const char *s2, const char *s3) {
  int l1 = strlen(s1);
  int l2 = strlen(s2);
  int l3 = strlen(s3) + 1;
  char *str = (char *)malloc(l1 + l2 + l3);
  memcpy(str, s1, l1);
  memcpy(str + l1, s2, l2);
  memcpy(str + l1 + l2, s3, l3);
  return str;
}


x86 assembly (clang, -O0):
<strdup3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
add    -0x20(%rbp),%edi
add    -0x24(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%r13,1),%ecx
lea    0x1(%rax),%edx
mov    %edx,0x4(%rsp)
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rbx
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
movslq %r13d,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    0x4(%rsp),%edx
call   1040 <memcpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @strdup3(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, 1
%8 = add nsw i32 %5, %4
%9 = add nsw i32 %8, %7
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @memcpy(i8* %11, i8* %0, i32 %4)
%13 = sext i32 %4 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = tail call i32 @memcpy(i8* %14, i8* %1, i32 %5)
%16 = sext i32 %5 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = tail call i32 @memcpy(i8* %17, i8* %2, i32 %7)
ret i8* %11
}