#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 */
scalar_t__ safe_malloc(char *, int, int);
int strlen(char const *);
char *copy_folder_name(const char *start, const char *end) {
  char *p;
  const char *q;
  int len;
  char *result;
  if (end) {
    len = end - start;
  } else {
    len = strlen(start);
  }
  result = (char *)safe_malloc(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/glob.c",
      254, sizeof(char) * (len + 1));
  for (p = result, q = start; end ? (q < end) : *q; q++) {
    if ((q[0] == '\\') && (q[1] == ':')) {
    } else {
      *p++ = *q;
    }
  }
  *p = '\0';
  return result;
}


x86 assembly (clang, -O0):
<copy_folder_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114e <copy_folder_name+0x2e>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    115a <copy_folder_name+0x3a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
lea    0xe91(%rip),%rdi
mov    $0xfe,%esi
call   1030 <safe_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b0 <copy_folder_name+0x90>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <copy_folder_name+0x9a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    $0x0,%eax
je     1219 <copy_folder_name+0xf9>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11ec <copy_folder_name+0xcc>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
jne    11ec <copy_folder_name+0xcc>
jmp    1203 <copy_folder_name+0xe3>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1208 <copy_folder_name+0xe8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118d <copy_folder_name+0x6d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_folder_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
je     1136 <copy_folder_name+0x16>
mov    %r14d,%edx
sub    %ebx,%edx
jmp    1140 <copy_folder_name+0x20>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
add    $0x1,%edx
lea    0xeb6(%rip),%rdi
mov    $0xfe,%esi
call   1030 <safe_malloc@plt>
mov    %rax,%rcx
jmp    116a <copy_folder_name+0x4a>
nopl   0x0(%rax)
mov    %dl,(%rcx)
add    $0x1,%rcx
add    $0x1,%rbx
test   %r14,%r14
je     1180 <copy_folder_name+0x60>
xor    %edx,%edx
cmp    %r14,%rbx
setb   %dl
test   %edx,%edx
jne    1187 <copy_folder_name+0x67>
jmp    1197 <copy_folder_name+0x77>
nopl   (%rax)
movsbl (%rbx),%edx
test   %edx,%edx
je     1197 <copy_folder_name+0x77>
movzbl (%rbx),%edx
cmp    $0x5c,%dl
jne    1160 <copy_folder_name+0x40>
cmpb   $0x3a,0x1(%rbx)
jne    1160 <copy_folder_name+0x40>
jmp    1166 <copy_folder_name+0x46>
movb   $0x0,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [126 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/glob.c\00"
define i8* @copy_folder_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
br label %21
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @safe_malloc(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0), i32 254, i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %8
%29 = load i8*, i8** %8
store i8* %29, i8** %5
%30 = load i8*, i8** %3
store i8* %30, i8** %6
br label %31
31: ; preds = %65, %21
%32 = load i8*, i8** %4
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8*, i8** %6
%36 = load i8*, i8** %4
%37 = icmp ult i8* %35, %36
%38 = zext i1 %37 to i32
br label %43
39: ; preds = %31
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
br label %43
43: ; preds = %39, %34
%44 = phi i32 [ %38, %34 ], [ %42, %39 ]
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %68
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 92
br i1 %51, label %52, label %59
52: ; preds = %46
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 58
br i1 %57, label %58, label %59
58: ; preds = %52
br label %64
59: ; preds = %52, %46
%60 = load i8*, i8** %6
%61 = load i8, i8* %60
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %5
store i8 %61, i8* %62
br label %64
64: ; preds = %59, %58
br label %65
65: ; preds = %64
%66 = load i8*, i8** %6
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %6
br label %31
68: ; preds = %43
%69 = load i8*, i8** %5
store i8 0, i8* %69
%70 = load i8*, i8** %8
ret i8* %70
}

LLVM IR (-O2):
@.str = [126 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/glob.c\00"
define i8* @copy_folder_name(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
br label %11
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %0)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %8, %4 ], [ %10, %9 ]
%13 = add nsw i32 %12, 1
%14 = tail call i64 @safe_malloc(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0), i32 254, i32 %13)
%15 = inttoptr i64 %14 to i8*
br label %16
16: ; preds = %37, %11
%17 = phi i8* [ %0, %11 ], [ %39, %37 ]
%18 = phi i8* [ %15, %11 ], [ %38, %37 ]
br i1 %3, label %22, label %19
19: ; preds = %16
%20 = icmp ult i8* %17, %1
%21 = zext i1 %20 to i32
br label %25
22: ; preds = %16
%23 = load i8, i8* %17
%24 = sext i8 %23 to i32
br label %25
25: ; preds = %22, %19
%26 = phi i32 [ %21, %19 ], [ %24, %22 ]
%27 = icmp eq i32 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %25
%29 = load i8, i8* %17
%30 = icmp eq i8 %29, 92
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %17, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 58
br i1 %34, label %37, label %35
35: ; preds = %31, %28
%36 = getelementptr inbounds i8, i8* %18, i64 1
store i8 %29, i8* %18
br label %37
37: ; preds = %35, %31
%38 = phi i8* [ %18, %31 ], [ %36, %35 ]
%39 = getelementptr inbounds i8, i8* %17, i64 1
br label %16
40: ; preds = %25
store i8 0, i8* %18
ret i8* %15
}