#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int file_pathcat(char *buf, char *pathname, char *filename, int length) {
  int pathlength = strlen(pathname);
  if ((pathlength + strlen(filename) + 1) >= length) {
    return 0;
  }
  strcpy(buf, pathname);
  if (buf[pathlength - 1] != '/') {
    buf[pathlength] = '/';
    buf[pathlength + 1] = '\0';
  }
  strcat(buf, filename);
  return 1;
}


x86 assembly (clang, -O0):
<file_pathcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    -0x24(%rbp),%eax
jl     1181 <file_pathcat+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <file_pathcat+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11c5 <file_pathcat+0x95>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_pathcat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ecx
add    $0x1,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jge    1197 <file_pathcat+0x67>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
movslq %ebx,%rax
cmpb   $0x2f,-0x1(%rax,%r15,1)
je     1187 <file_pathcat+0x57>
lea    0x1(%rax),%ecx
movb   $0x2f,(%r15,%rax,1)
movslq %ecx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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