#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(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
int cat_domain(const char *name, const char *domain, char **s) {
  size_t nlen = strlen(name);
  size_t dlen = strlen(domain);
  *s = malloc(nlen + 1 + dlen + 1);
  if (!*s)
    return 15;
  memcpy(*s, name, nlen);
  (*s)[nlen] = '.';
  memcpy(*s + nlen + 1, domain, dlen);
  (*s)[nlen + 1 + dlen] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<cat_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
add    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1197 <cat_domain+0x67>
movl   $0xf,-0x4(%rbp)
jmp    11f4 <cat_domain+0xc4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
add    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat_domain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11aa <cat_domain+0x7a>
lea    (%rbx,%r12,1),%rbp
add    $0x1,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    (%r15),%rax
movb   $0x2e,(%rax,%rbx,1)
mov    (%r15),%rax
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbp,1)
xor    %eax,%eax
jmp    11af <cat_domain+0x7f>
mov    $0xf,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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