#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *strdup_pathcat(const char *p0, const char *p1) {
  char *p;
  size_t n0, n1, na;
  n0 = strlen(p0);
  n1 = strlen(p1);
  na = n0 + n1 + 1;
  if (p0[n0 - 1] != '/') {
    na++;
  }
  p = malloc(na);
  strcpy(p, p0);
  if (p0[n0 - 1] != '/') {
    p[n0] = '/';
  }
  strcat(p, p1);
  return p;
}


x86 assembly (clang, -O0):
<strdup_pathcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     119f <strdup_pathcat+0x5f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11de <strdup_pathcat+0x9e>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_pathcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmpb   $0x2f,-0x1(%r15,%r12,1)
lea    (%rax,%r15,1),%rdi
sete   %cl
sub    %rcx,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
cmpb   $0x2f,-0x1(%r15,%r12,1)
je     1194 <strdup_pathcat+0x54>
movb   $0x2f,(%rbx,%r15,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strdup_pathcat(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, %3
%6 = add i64 %3, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = select i1 %9, i64 1, i64 2
%11 = add i64 %5, %10
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 47
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = getelementptr inbounds i8, i8* %12, i64 %3
store i8 47, i8* %17
br label %18
18: ; preds = %16, %2
%19 = tail call i32 @strcat(i8* %12, i8* %1)
ret i8* %12
}