#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 *mem_zalloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int strlen(char const *);
char *fp_join(const char *p1, const char *p2) {
  int len = strlen(p1) + strlen(p2) + 2;
  char *p3 = NULL;
  if (!(p3 = mem_zalloc(len))) {
    goto EXIT;
  }
  snprintf(p3, len, "%s/%s", p1, p2);
EXIT:
  return p3;
}


x86 assembly (clang, -O0):
<fp_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <mem_zalloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1185 <fp_join+0x55>
jmp    11a0 <fp_join+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe65(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_join>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x2,%ebp
mov    %ebp,%edi
call   1040 <mem_zalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1178 <fp_join+0x48>
lea    0xe98(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
define i8* @fp_join(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 2
store i32 %12, i32* %5
store i8* null, i8** %6
%13 = load i32, i32* %5
%14 = call i8* @mem_zalloc(i32 %13)
store i8* %14, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
br label %23
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
br label %23
23: ; preds = %17, %16
%24 = load i8*, i8** %6
ret i8* %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i8* @fp_join(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i8* @mem_zalloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @snprintf(i8* %7, i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %11
11: ; preds = %2, %9
ret i8* %7
}