#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 */
struct ext2_fs {
  int dummy;
};

/* Variables and functions */
int ext2_find_child(struct ext2_fs *, char *, int);
char *strtok(char *, char *);
int pathize(struct ext2_fs *f, char *path) {
  char *pch = strtok(path, "/");
  int parent = 2;
  while (pch) {
    parent = ext2_find_child(f, pch, parent);
    pch = strtok(NULL, "/");
  }
  return parent;
}


x86 assembly (clang, -O0):
<pathize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1182 <pathize+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <ext2_find_child@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe8c(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    114b <pathize+0x2b>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathize>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xecf(%rip),%rsi
mov    %rax,%rdi
call   1030 <strtok@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     116e <pathize+0x4e>
lea    0xeb6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1040 <ext2_find_child@plt>
mov    %eax,%ebp
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
jne    1150 <pathize+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ext2_fs = type { i32 }
@.str = [2 x i8] c"/\00"
define i32 @pathize(%struct.ext2_fs* %0, i8* %1) {
%3 = alloca %struct.ext2_fs*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store %struct.ext2_fs* %0, %struct.ext2_fs** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %5
store i32 2, i32* %6
br label %9
9: ; preds = %12, %2
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load %struct.ext2_fs*, %struct.ext2_fs** %3
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = call i32 @ext2_find_child(%struct.ext2_fs* %13, i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %5
br label %9
18: ; preds = %9
%19 = load i32, i32* %6
ret i32 %19
}

LLVM IR (-O2):
%struct.ext2_fs = type { i32 }
@.str = [2 x i8] c"/\00"
define i32 @pathize(%struct.ext2_fs* %0, i8* %1) {
%3 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ 2, %2 ]
%7 = phi i8* [ %9, %5 ], [ %3, %2 ]
%8 = tail call i32 @ext2_find_child(%struct.ext2_fs* %0, i8* %7, i32 %6)
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %5
11: ; preds = %5, %2
%12 = phi i32 [ 2, %2 ], [ %8, %5 ]
ret i32 %12
}