#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 */
typedef int /*<<< orphan*/ number;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
int convertPath(char *path, unsigned int *pathBinary) {
  int index = 0;
  char *pathComponent = strtok(path, "/");
  while (pathComponent != NULL) {
    char number[20];
    unsigned char isHardened = 0;
    if (index == 10) {
      return -1;
    }
    strncpy(number, pathComponent, sizeof(number));
    number[sizeof(number) - 1] = '\0';
    if (number[strlen(number) - 1] == '\'') {
      isHardened = 1;
      number[strlen(number) - 1] = '\0';
    }
    pathBinary[index] = strtol(number, NULL, 10);
    if (isHardened) {
      pathBinary[index] |= 0x80000000;
    }
    index++;
    pathComponent = strtok(NULL, "/");
  }
  return index;
}


x86 assembly (clang, -O0):
<convertPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1238 <convertPath+0xf8>
movb   $0x0,-0x41(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1190 <convertPath+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    123e <convertPath+0xfe>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x2d(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x27,%eax
jne    11d9 <convertPath+0x99>
movb   $0x1,-0x41(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
cmpb   $0x0,-0x41(%rbp)
je     1216 <convertPath+0xd6>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
or     $0x80000000,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd6(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    116b <convertPath+0x2b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertPath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
lea    0xeaa(%rip),%rsi
call   1060 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11fd <convertPath+0xbd>
mov    %rsp,%r15
lea    0xe90(%rip),%r12
jmp    11b5 <convertPath+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
or     $0x80000000,%ecx
cmp    $0x27,%bpl
cmovne %eax,%ecx
mov    %ecx,(%r14,%rbx,4)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11fd <convertPath+0xbd>
cmp    $0xa,%rbx
je     11f8 <convertPath+0xb8>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x13(%rsp)
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movzbl -0x1(%rax,%r15,1),%ebp
cmp    $0x27,%bpl
jne    1180 <convertPath+0x40>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
jmp    1180 <convertPath+0x40>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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