#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 atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *strsep(char **, char *);
int detoken(char *pbkstr, char **sha, int *iter, char **salt, char **key) {
  char *p, *s, *save;
  int rc = 1;
  save = s = strdup(pbkstr);
  if ((p = strsep(&s, "$")) == NULL)
    goto out;
  if (strcmp(p, "PBKDF2") != 0)
    goto out;
  if ((p = strsep(&s, "$")) == NULL)
    goto out;
  *sha = strdup(p);
  if ((p = strsep(&s, "$")) == NULL)
    goto out;
  *iter = atoi(p);
  if ((p = strsep(&s, "$")) == NULL)
    goto out;
  *salt = strdup(p);
  if ((p = strsep(&s, "$")) == NULL)
    goto out;
  *key = strdup(p);
  rc = 0;
out:
  free(save);
  return rc;
}


x86 assembly (clang, -O0):
<detoken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    %rax,-0x40(%rbp)
lea    -0x38(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a7 <detoken+0x57>
jmp    12a3 <detoken+0x153>
mov    -0x30(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11c6 <detoken+0x76>
jmp    12a3 <detoken+0x153>
lea    -0x38(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11e9 <detoken+0x99>
jmp    12a3 <detoken+0x153>
mov    -0x30(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x38(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    121f <detoken+0xcf>
jmp    12a3 <detoken+0x153>
mov    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x38(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1253 <detoken+0x103>
jmp    12a3 <detoken+0x153>
mov    -0x30(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x38(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1289 <detoken+0x139>
jmp    12a3 <detoken+0x153>
mov    -0x30(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detoken>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
lea    0xe86(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11a0 <detoken+0x50>
lea    0xe6f(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b9 <detoken+0x69>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe40(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     11a0 <detoken+0x50>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,0x0(%r13)
lea    0xe20(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     11a0 <detoken+0x50>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r12)
lea    0xe00(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     11a0 <detoken+0x50>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r15)
lea    0xde1(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     11a0 <detoken+0x50>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14)
xor    %ebp,%ebp
jmp    11a0 <detoken+0x50>

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

LLVM IR (-O2):
@.str = [2 x i8] c"$\00"
@.str.1 = [7 x i8] c"PBKDF2\00"
define i32 @detoken(i8* nocapture %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2, i8** nocapture writeonly %3, i8** nocapture writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = tail call i8* @strdup(i8* %0)
store i8* %8, i8** %6
%9 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %31, label %11
11: ; preds = %5
%12 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = call i8* @strdup(i8* %15)
store i8* %18, i8** %1
%19 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = call i32 @atoi(i8* %19)
store i32 %22, i32* %2
%23 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %31, label %25
25: ; preds = %21
%26 = call i8* @strdup(i8* %23)
store i8* %26, i8** %3
%27 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i8* @strdup(i8* %27)
store i8* %30, i8** %4
br label %31
31: ; preds = %25, %21, %17, %14, %11, %5, %29
%32 = phi i32 [ 1, %5 ], [ 1, %11 ], [ 1, %14 ], [ 1, %17 ], [ 1, %21 ], [ 1, %25 ], [ 0, %29 ]
%33 = call i32 @free(i8* %8)
ret i32 %32
}