#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*/ strcpy(char *, ...);
char *strtok(char *, char *);
int path_parser(char *path, char *pathfound) {
  char *token;
  char aux[2048];
  strcpy(aux, path);
  int char_size = 1;
  token = strtok(aux, "/");
  while (token != NULL) {
    token = strtok(NULL, "/");
    ++char_size;
  }
  const char *paths[char_size];
  strcpy(aux, path);
  char_size = 0;
  token = strtok(aux, "/");
  while (token != NULL) {
    paths[char_size] = token;
    ++char_size;
    token = strtok(NULL, "/");
  }
  strcpy(pathfound, paths);
  return char_size;
}


x86 assembly (clang, -O0):
<path_parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
call   1030 <strcpy@plt>
movl   $0x1,-0x824(%rbp)
lea    -0x820(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <path_parser+0x79>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe84(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x824(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x824(%rbp)
jmp    1166 <path_parser+0x46>
mov    -0x824(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x830(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x840(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x838(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
call   1030 <strcpy@plt>
movl   $0x0,-0x824(%rbp)
lea    -0x820(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1248 <path_parser+0x128>
mov    -0x840(%rbp),%rax
mov    -0x18(%rbp),%rdx
movslq -0x824(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x824(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x824(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc6(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    11ff <path_parser+0xdf>
mov    -0x840(%rbp),%rsi
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
call   1030 <strcpy@plt>
mov    -0x824(%rbp),%eax
mov    -0x830(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_parser>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r15
xor    %r14d,%r14d
lea    -0x840(%rbp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <strcpy@plt>
lea    0xea7(%rip),%rsi
mov    %r12,%rdi
call   1040 <strtok@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1193 <path_parser+0x73>
lea    0xe8e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r12,%rsi
call   1040 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <path_parser+0x60>
mov    %rsp,-0x30(%rbp)
mov    %rsp,%r12
lea    0xf(,%rbx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x840(%rbp),%r13
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <strcpy@plt>
lea    0xe39(%rip),%rsi
mov    %r13,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11f7 <path_parser+0xd7>
xor    %r14d,%r14d
lea    0xe22(%rip),%r15
xchg   %ax,%ax
mov    %rax,(%r12,%r14,8)
add    $0x1,%r14
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    11e0 <path_parser+0xc0>
mov    -0x38(%rbp),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @path_parser(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [2048 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @strcpy(i8* %10, i8* %11)
store i32 1, i32* %7
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %5
br label %15
15: ; preds = %18, %2
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %5
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %15
22: ; preds = %15
%23 = load i32, i32* %7
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %8
%26 = alloca i8*, i64 %24
store i64 %24, i64* %9
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%28 = load i8*, i8** %3
%29 = call i32 (i8*, ...) @strcpy(i8* %27, i8* %28)
store i32 0, i32* %7
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %31, i8** %5
br label %32
32: ; preds = %35, %22
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %26, i64 %38
store i8* %36, i8** %39
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %42, i8** %5
br label %32
43: ; preds = %32
%44 = load i8*, i8** %4
%45 = call i32 (i8*, ...) @strcpy(i8* %44, i8** %26)
%46 = load i32, i32* %7
%47 = load i8*, i8** %8
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @path_parser(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, ...) @strcpy(i8* %4, i8* %0)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 1, %2 ]
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i8* %10, null
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = zext i32 %11 to i64
br label %15
15: ; preds = %13, %2
%16 = phi i64 [ 1, %2 ], [ %14, %13 ]
%17 = call i8* @llvm.stacksave()
%18 = alloca i8*, i64 %16
%19 = call i32 (i8*, ...) @strcpy(i8* %4, i8* %0)
%20 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %31, label %22
22: ; preds = %15, %22
%23 = phi i64 [ %26, %22 ], [ 0, %15 ]
%24 = phi i8* [ %27, %22 ], [ %20, %15 ]
%25 = getelementptr inbounds i8*, i8** %18, i64 %23
store i8* %24, i8** %25
%26 = add nuw i64 %23, 1
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %22
29: ; preds = %22
%30 = trunc i64 %26 to i32
br label %31
31: ; preds = %29, %15
%32 = phi i32 [ 0, %15 ], [ %30, %29 ]
%33 = call i32 (i8*, ...) @strcpy(i8* %1, i8** %18)
ret i32 %32
}