#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__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void prepara_string(char **caminho) {
  int tamanho = strlen(*caminho), x = 0, posicao = 0;
  char temp[256], letra[2];
  strcpy(temp, *caminho);
  for (x = 0; x < tamanho; x++) {
    strncpy(letra, temp + x, 1);
    if (strcmp("\\", letra) == 0)
      posicao = x;
    if (strcmp("/", letra) == 0)
      posicao = x;
  }
  if (posicao > 0) {
    posicao++;
    strncpy(temp, *caminho + posicao, tamanho);
  }
  strcpy(*caminho, temp);
}


x86 assembly (clang, -O0):
<prepara_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120a <prepara_string+0xca>
lea    -0x122(%rbp),%rdi
lea    -0x120(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0x122(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <prepara_string+0x94>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x122(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <prepara_string+0xb7>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11fc <prepara_string+0xbc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <prepara_string+0x46>
cmpl   $0x0,-0x14(%rbp)
jle    123a <prepara_string+0xfa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x120(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepara_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbp
mov    (%rdi),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
test   %ebx,%ebx
jle    11ff <prepara_string+0xbf>
mov    %rbp,0x8(%rsp)
mov    %ebx,%r15d
xor    %r14d,%r14d
lea    0x6(%rsp),%rbx
lea    0xe77(%rip),%r13
xor    %r12d,%r12d
xchg   %ax,%ax
lea    (%rsp,%r14,1),%rsi
add    $0x10,%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <strncpy@plt>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rbp,%rbp
cmove  %r14d,%r12d
test   %rax,%rax
cmove  %r14d,%r12d
add    $0x1,%r14
cmp    %r14,%r15
jne    1190 <prepara_string+0x50>
test   %r12d,%r12d
mov    0x8(%rsp),%rbp
jle    11ff <prepara_string+0xbf>
mov    0x0(%rbp),%rax
mov    %r12d,%ecx
lea    (%rcx,%rax,1),%rsi
add    $0x1,%rsi
lea    0x10(%rsp),%rdi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    0x0(%rbp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <strcpy@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\\\00"
@.str.1 = [2 x i8] c"/\00"
define void @prepara_string(i8** nocapture %0) {
%2 = alloca [256 x i8]
%3 = alloca [2 x i8]
%4 = load i8*, i8** %0
%5 = tail call i32 @strlen(i8* %4)
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%8 = load i8*, i8** %0
%9 = call i32 @strcpy(i8* %6, i8* %8)
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %35
11: ; preds = %1
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %25, %13 ]
%15 = phi i32 [ 0, %11 ], [ %24, %13 ]
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %14
%17 = call i32 @strncpy(i8* %7, i8* %16, i32 1)
%18 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %7)
%19 = icmp eq i64 %18, 0
%20 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i1 true, i1 %19
%23 = trunc i64 %14 to i32
%24 = select i1 %22, i32 %23, i32 %15
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %13
27: ; preds = %13
%28 = icmp sgt i32 %24, 0
br i1 %28, label %29, label %35
29: ; preds = %27
%30 = add nuw nsw i32 %24, 1
%31 = load i8*, i8** %0
%32 = zext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = call i32 @strncpy(i8* %6, i8* %33, i32 %5)
br label %35
35: ; preds = %1, %29, %27
%36 = load i8*, i8** %0
%37 = call i32 @strcpy(i8* %36, i8* %6)
ret void
}