#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*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int path_reformat(char *path) {
  char *pch;
  char new_path[PATH_MAX];
  if (path == NULL)
    return -1;
  pch = strstr("./", path);
  if (pch == path)
    return 0;
  if (path[0] == '/')
    return 0;
  sprintf(new_path, "./%s", path);
  strcpy(path, new_path);
  return 0;
}


x86 assembly (clang, -O0):
<path_reformat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <path_reformat+0x56>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120d <path_reformat+0xdd>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11bb <path_reformat+0x8b>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120d <path_reformat+0xdd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11de <path_reformat+0xae>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120d <path_reformat+0xdd>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe16(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_reformat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdi,%rdi
je     1198 <path_reformat+0x68>
mov    %rdi,%r15
lea    0xe9d(%rip),%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
xor    %r14d,%r14d
cmp    %r15,%rax
je     119e <path_reformat+0x6e>
cmpb   $0x2f,(%r15)
je     119e <path_reformat+0x6e>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    119e <path_reformat+0x6e>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"./\00"
@.str.1 = [5 x i8] c"./%s\00"
define i32 @path_reformat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %7
br label %34
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i8* @strstr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %2
store i32 1, i32* %7
br label %34
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %2
store i32 1, i32* %7
br label %34
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %32, i8* %11)
store i32 0, i32* %2
store i32 1, i32* %7
br label %34
34: ; preds = %29, %28, %21, %14
%35 = load i8*, i8** %5
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"./\00"
@.str.1 = [5 x i8] c"./%s\00"
define i32 @path_reformat(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp eq i8* %0, null
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = tail call i8* @strstr(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = icmp eq i8* %7, %0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 47
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = call i32 @strcpy(i8* %0, i8* %4)
br label %15
15: ; preds = %9, %6, %1, %12
%16 = phi i32 [ 0, %12 ], [ -1, %1 ], [ 0, %6 ], [ 0, %9 ]
ret i32 %16
}