#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(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *upb_join(char *base, char *name) {
  if (!base || strlen(base) == 0) {
    return strdup(name);
  } else {
    char *ret = malloc(strlen(base) + strlen(name) + 2);
    ret[0] = '\0';
    strcat(ret, base);
    strcat(ret, ".");
    strcat(ret, name);
    return ret;
  }
}


x86 assembly (clang, -O0):
<upb_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116e <upb_join+0x2e>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1180 <upb_join+0x40>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11e3 <upb_join+0xa3>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upb_join>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11a6 <upb_join+0x66>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     11a6 <upb_join+0x66>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <strdup@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @upb_join(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9, %2
%14 = load i8*, i8** %5
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %3
br label %35
16: ; preds = %9
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %18, %20
%22 = add nsw i64 %21, 2
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 0, i8* %25
%26 = load i8*, i8** %6
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %6
%32 = load i8*, i8** %5
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %6
store i8* %34, i8** %3
br label %35
35: ; preds = %16, %13
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @upb_join(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4, %2
%8 = tail call i8* @strdup(i8* %1)
br label %17
9: ; preds = %4
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %5, 2
%12 = add i64 %11, %10
%13 = tail call i8* @malloc(i64 %12)
store i8 0, i8* %13
%14 = tail call i32 @strcat(i8* %13, i8* %0)
%15 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @strcat(i8* %13, i8* %1)
br label %17
17: ; preds = %9, %7
%18 = phi i8* [ %8, %7 ], [ %13, %9 ]
ret i8* %18
}