#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 copy_file(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int copy_callback(char *source_root, char *source, char *target_root) {
  if (source_root[strlen(source_root) - 1] == '/')
    source_root[strlen(source_root) - 1] = 0;
  if (target_root[strlen(target_root) - 1] == '/')
    target_root[strlen(target_root) - 1] = 0;
  if (strstr(source, source_root) != source)
    return -1;
  char target[strlen(source) + strlen(target_root) + 1];
  target[0] = 0;
  strcat(target, target_root);
  strcat(target, source + strlen(source_root));
  return copy_file(source, target);
}


x86 assembly (clang, -O0):
<copy_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    119f <copy_callback+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11ea <copy_callback+0xaa>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
cmp    -0x18(%rbp),%rax
je     120d <copy_callback+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <copy_callback+0x158>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movb   $0x0,(%rdi)
mov    -0x20(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
cltq
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1030 <copy_file@plt>
mov    %eax,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_callback>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1174 <copy_callback+0x34>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
jne    1196 <copy_callback+0x56>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    121d <copy_callback+0xdd>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r13
add    %r12d,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
mov    %rcx,%r12
sub    %rax,%r12
neg    %rax
mov    %r12,%rsp
movb   $0x0,(%rcx,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rsi
add    %r14,%rsi
mov    %r12,%rdi
call   1060 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <copy_file@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @copy_callback(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 47
br i1 %18, label %19, label %26
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %19, %3
%27 = load i8*, i8** %7
%28 = load i8*, i8** %7
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %43
36: ; preds = %26
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %36, %26
%44 = load i8*, i8** %6
%45 = load i8*, i8** %5
%46 = call i8* @strstr(i8* %44, i8* %45)
%47 = load i8*, i8** %6
%48 = icmp ne i8* %46, %47
br i1 %48, label %49, label %50
49: ; preds = %43
store i32 -1, i32* %4
br label %72
50: ; preds = %43
%51 = load i8*, i8** %6
%52 = call i32 @strlen(i8* %51)
%53 = load i8*, i8** %7
%54 = call i32 @strlen(i8* %53)
%55 = add nsw i32 %52, %54
%56 = add nsw i32 %55, 1
%57 = zext i32 %56 to i64
%58 = call i8* @llvm.stacksave()
store i8* %58, i8** %8
%59 = alloca i8, i64 %57
store i64 %57, i64* %9
%60 = getelementptr inbounds i8, i8* %59, i64 0
store i8 0, i8* %60
%61 = load i8*, i8** %7
%62 = call i32 @strcat(i8* %59, i8* %61)
%63 = load i8*, i8** %6
%64 = load i8*, i8** %5
%65 = call i32 @strlen(i8* %64)
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
%68 = call i32 @strcat(i8* %59, i8* %67)
%69 = load i8*, i8** %6
%70 = call i32 @copy_file(i8* %69, i8* %59)
store i32 %70, i32* %4
%71 = load i8*, i8** %8
br label %72
72: ; preds = %50, %49
%73 = load i32, i32* %4
ret i32 %73
}

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