#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(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *fconcat(const char *p1, const char *p2) {
  int len;
  char *new;
  len = strlen(p1);
  while (len > 0 && p1[len - 1] == '/')
    --len;
  new = malloc(len + 2 + strlen(p2));
  memcpy(new, p1, len);
  new[len++] = '/';
  strcpy(new + len, p2);
  return new;
}


x86 assembly (clang, -O0):
<fconcat>:
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    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jle    1185 <fconcat+0x45>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1195 <fconcat+0x55>
jmp    11a3 <fconcat+0x63>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <fconcat+0x1c>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%edi
add    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fconcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %r15d,%r15d
test   %eax,%eax
cmovs  %eax,%r15d
xchg   %ax,%ax
test   %ecx,%ecx
jle    1178 <fconcat+0x38>
lea    -0x1(%rcx),%rax
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
mov    %rax,%rcx
je     1160 <fconcat+0x20>
add    $0x1,%eax
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movslq %r15d,%rax
movb   $0x2f,(%r12,%rax,1)
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @fconcat(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
%5 = call i32 @llvm.smin.i32(i32 %3, i32 0)
br label %6
6: ; preds = %10, %2
%7 = phi i64 [ %11, %10 ], [ %4, %2 ]
%8 = trunc i64 %7 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = add nsw i64 %7, -1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %6, label %15
15: ; preds = %10
%16 = trunc i64 %7 to i32
br label %17
17: ; preds = %6, %15
%18 = phi i32 [ %16, %15 ], [ %5, %6 ]
%19 = add nsw i32 %18, 2
%20 = tail call i32 @strlen(i8* %1)
%21 = add nsw i32 %19, %20
%22 = tail call i8* @malloc(i32 %21)
%23 = tail call i32 @memcpy(i8* %22, i8* %0, i32 %18)
%24 = add nsw i32 %18, 1
%25 = sext i32 %18 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 47, i8* %26
%27 = sext i32 %24 to i64
%28 = getelementptr inbounds i8, i8* %22, i64 %27
%29 = tail call i32 @strcpy(i8* %28, i8* %1)
ret i8* %22
}