#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 PATH_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *,
                           char const *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int _strcat(int base, char *path, const char *name) {
  int new_len, name_len;
  name_len = strlen(name);
  new_len = base + name_len;
  if (new_len >= PATH_MAX) {
    path[base] = '\0';
    fprintf(stderr,
            "ERROR: path concatenation too long %d of %d "
            "available: \"%s\" + \"%s\"\n",
            new_len, PATH_MAX, path, name);
    return -1;
  }
  memcpy(path + base, name, name_len + 1);
  return new_len;
}


x86 assembly (clang, -O0):
<_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jl     11ab <_strcat+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <_strcat+0x9b>
mov    -0x10(%rbp),%rdi
movslq -0x8(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strcat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%ebp
mov    0x2e9f(%rip),%rcx
movslq %ebx,%rdi
add    %r14,%rdi
cmp    (%rcx),%ebp
jge    116a <_strcat+0x3a>
add    $0x1,%eax
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
jmp    1191 <_strcat+0x61>
movb   $0x0,(%rdi)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    (%rcx),%ecx
lea    0xe81(%rip),%rsi
mov    %ebp,%edx
mov    %r14,%r8
mov    %r15,%r9
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [68 x i8] c"ERROR: path concatenation too long %d of %d available: \22%s\22 + \22%s\22\0A\00"
define i32 @_strcat(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = load i32, i32* %5
%13 = load i32, i32* %9
%14 = add nsw i32 %12, %13
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = load i32, i32* @PATH_MAX
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = load i32, i32* @stderr
%24 = load i32, i32* %8
%25 = load i32, i32* @PATH_MAX
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25, i8* %26, i8* %27)
store i32 -1, i32* %4
br label %39
29: ; preds = %3
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8*, i8** %7
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = call i32 @memcpy(i8* %33, i8* %34, i32 %36)
%38 = load i32, i32* %8
store i32 %38, i32* %4
br label %39
39: ; preds = %29, %18
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [68 x i8] c"ERROR: path concatenation too long %d of %d available: \22%s\22 + \22%s\22\0A\00"
define i32 @_strcat(i32 %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = add nsw i32 %4, %0
%6 = load i32, i32* @PATH_MAX
%7 = icmp slt i32 %5, %6
%8 = sext i32 %0 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
br i1 %7, label %14, label %10
10: ; preds = %3
store i8 0, i8* %9
%11 = load i32, i32* @stderr
%12 = load i32, i32* @PATH_MAX
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %12, i8* %1, i8* %2)
br label %17
14: ; preds = %3
%15 = add nsw i32 %4, 1
%16 = tail call i32 @memcpy(i8* %9, i8* %2, i32 %15)
br label %17
17: ; preds = %14, %10
%18 = phi i32 [ -1, %10 ], [ %5, %14 ]
ret i32 %18
}