#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 ENAMETOOLONG;
size_t PATH_MAX;
int /*<<< orphan*/ __strncpy_null(char *, char const *, int);
size_t strlen(char const *);
int arg_copy_path(char *dest, const char *src, int destlen) {
  size_t len = strlen(src);
  if (len >= PATH_MAX || len >= destlen)
    return -ENAMETOOLONG;
  __strncpy_null(dest, src, destlen);
  return 0;
}


x86 assembly (clang, -O0):
<arg_copy_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%rax
jae    1165 <arg_copy_path+0x45>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jb     1178 <arg_copy_path+0x58>
xor    %eax,%eax
mov    0x2e6a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <arg_copy_path+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <__strncpy_null@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_copy_path>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
movslq %ebp,%rcx
cmp    %rcx,%rax
jae    1159 <arg_copy_path+0x39>
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%rax
jae    1159 <arg_copy_path+0x39>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <__strncpy_null@plt>
xor    %eax,%eax
jmp    1164 <arg_copy_path+0x44>
mov    0x2e78(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i64 0
@ENAMETOOLONG = global i32 0
define i32 @arg_copy_path(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i64, i64* %8
%12 = load i64, i64* @PATH_MAX
%13 = icmp uge i64 %11, %12
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = load i64, i64* %8
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = icmp uge i64 %15, %17
br i1 %18, label %19, label %22
19: ; preds = %14, %3
%20 = load i32, i32* @ENAMETOOLONG
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %27
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @__strncpy_null(i8* %23, i8* %24, i32 %25)
store i32 0, i32* %4
br label %27
27: ; preds = %22, %19
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@PATH_MAX = global i64 0
@ENAMETOOLONG = global i32 0
define i32 @arg_copy_path(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = load i64, i64* @PATH_MAX
%6 = icmp ult i64 %4, %5
%7 = sext i32 %2 to i64
%8 = icmp ult i64 %4, %7
%9 = and i1 %8, %6
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* @ENAMETOOLONG
%12 = sub nsw i32 0, %11
br label %15
13: ; preds = %3
%14 = tail call i32 @__strncpy_null(i8* %0, i8* %1, i32 %2)
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ 0, %13 ]
ret i32 %16
}