#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*/ memcpy(char *, char const *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char const *);
void move_into_directory(const char *dname, char *abs_path) {
  if (strcmp(abs_path, "/") != 0) {
    int abs_path_len = strlen(abs_path);
    if ((abs_path_len + strlen(dname) + 1) >= (256 - 1)) {
      abs_path[0] = '\0';
      return;
    }
    memcpy(abs_path + abs_path_len, "/", 1);
    memcpy(abs_path + abs_path_len + 1, dname, strlen(dname) + 1);
  } else {
    int abs_path_len = strlen(abs_path);
    if ((abs_path_len + strlen(dname)) >= (256 - 1)) {
      abs_path[0] = '\0';
      return;
    }
    memcpy(abs_path + strlen(abs_path), dname, strlen(dname) + 1);
  }
}


x86 assembly (clang, -O0):
<move_into_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11ed <move_into_directory+0xbd>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    $0xff,%eax
jl     1196 <move_into_directory+0x66>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    126a <move_into_directory+0x13a>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xe58(%rip),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
jmp    126a <move_into_directory+0x13a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
cmp    $0xff,%eax
jl     1226 <move_into_directory+0xf6>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    126a <move_into_directory+0x13a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_into_directory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
test   %r15,%r15
je     119e <move_into_directory+0x6e>
cmp    $0xfe,%eax
jge    11a5 <move_into_directory+0x75>
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rdi
lea    0xe83(%rip),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
add    %rbp,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
jmp    11cf <move_into_directory+0x9f>
cmp    $0xff,%eax
jl     11b3 <move_into_directory+0x83>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <memcpy@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @move_into_directory(i8* %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, %5
br i1 %4, label %19, label %8
8: ; preds = %2
%9 = icmp sgt i32 %7, 253
br i1 %9, label %10, label %11
10: ; preds = %8
store i8 0, i8* %1
br label %29
11: ; preds = %8
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, 1
%18 = tail call i32 @memcpy(i8* %15, i8* %0, i32 %17)
br label %29
19: ; preds = %2
%20 = icmp sgt i32 %7, 254
br i1 %20, label %21, label %22
21: ; preds = %19
store i8 0, i8* %1
br label %29
22: ; preds = %19
%23 = tail call i32 @strlen(i8* %1)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = tail call i32 @strlen(i8* %0)
%27 = add nsw i32 %26, 1
%28 = tail call i32 @memcpy(i8* %25, i8* %0, i32 %27)
br label %29
29: ; preds = %21, %22, %10, %11
ret void
}