#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 */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlcatf(char *, int, char *, char *);
void concatenate_paths(char *buffer, int maxbufsize, char *p1, char *p2) {
  int i;
  memset(buffer, 0, maxbufsize);
  for (i = 0; (p1[i]) && (p1[i] != '/' || p1[i + 1]); i++)
    *(buffer++) = p1[i];
  *(buffer++) = '/';
  while (*p2 == '/')
    p2++;
  strlcatf(buffer, maxbufsize, "%s", p2);
}


x86 assembly (clang, -O0):
<concatenate_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     11a0 <concatenate_paths+0x80>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x2f,%ecx
mov    %al,-0x26(%rbp)
jne    119a <concatenate_paths+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b0 <concatenate_paths+0x90>
jmp    11da <concatenate_paths+0xba>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <concatenate_paths+0x2c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    120d <concatenate_paths+0xed>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ec <concatenate_paths+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xde1(%rip),%rdx
call   1040 <strlcatf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatenate_paths>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r12
xor    %ebp,%ebp
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
jmp    1161 <concatenate_paths+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,0x1(%r15,%rbp,1)
je     1172 <concatenate_paths+0x52>
add    $0x1,%rbp
mov    %al,-0x1(%r12)
add    $0x1,%r12
movzbl (%r15,%rbp,1),%eax
cmp    $0x2f,%al
je     1150 <concatenate_paths+0x30>
test   %al,%al
jne    1158 <concatenate_paths+0x38>
movb   $0x2f,-0x1(%r12)
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
cmpb   $0x2f,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1180 <concatenate_paths+0x60>
lea    0xe6f(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlcatf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @concatenate_paths(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @memset(i8* %10, i32 0, i32 %11)
store i32 0, i32* %9
br label %13
13: ; preds = %50, %4
%14 = load i8*, i8** %7
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %13
%22 = load i8*, i8** %7
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 47
br i1 %28, label %38, label %29
29: ; preds = %21
%30 = load i8*, i8** %7
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br label %38
38: ; preds = %29, %21
%39 = phi i1 [ true, %21 ], [ %37, %29 ]
br label %40
40: ; preds = %38, %13
%41 = phi i1 [ false, %13 ], [ %39, %38 ]
br i1 %41, label %42, label %53
42: ; preds = %40
%43 = load i8*, i8** %7
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %5
store i8 %47, i8* %48
br label %50
50: ; preds = %42
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %13
53: ; preds = %40
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
store i8 47, i8* %54
br label %56
56: ; preds = %61, %53
%57 = load i8*, i8** %8
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 47
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %8
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %8
br label %56
64: ; preds = %56
%65 = load i8*, i8** %5
%66 = load i32, i32* %6
%67 = load i8*, i8** %8
%68 = call i32 @strlcatf(i8* %65, i32 %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %67)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @concatenate_paths(i8* %0, i32 %1, i8* nocapture %2, i8* %3) {
%5 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
br label %6
6: ; preds = %18, %4
%7 = phi i64 [ %19, %18 ], [ 0, %4 ]
%8 = phi i8* [ %20, %18 ], [ %0, %4 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %7
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %21
i8 47, label %13
]
11: ; preds = %6
%12 = add nuw i64 %7, 1
br label %18
13: ; preds = %6
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %11, %13
%19 = phi i64 [ %12, %11 ], [ %14, %13 ]
%20 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %10, i8* %8
br label %6
21: ; preds = %6, %13
store i8 47, i8* %8
br label %22
22: ; preds = %22, %21
%23 = phi i8* [ %3, %21 ], [ %26, %22 ]
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
%26 = getelementptr inbounds i8, i8* %23, i64 1
br i1 %25, label %22, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %8, i64 1
%29 = tail call i32 @strlcatf(i8* %28, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
ret void
}