#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 */
char *strtok(char *, char *);
int loc_segments(char *text, char **a, char **b, char **c) {
  *a = strtok(text, "/");
  if (!*a)
    return 0;
  *b = strtok(NULL, "/");
  if (!*b)
    return 1;
  *c = strtok(NULL, "/");
  if (!*c)
    return 2;
  return 3;
}


x86 assembly (clang, -O0):
<loc_segments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    115c <loc_segments+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11cb <loc_segments+0xbb>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe99(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1190 <loc_segments+0x80>
movl   $0x1,-0x4(%rbp)
jmp    11cb <loc_segments+0xbb>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe65(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c4 <loc_segments+0xb4>
movl   $0x2,-0x4(%rbp)
jmp    11cb <loc_segments+0xbb>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loc_segments>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
lea    0xedb(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1167 <loc_segments+0x57>
lea    0xec7(%rip),%rsi
xor    %edi,%edi
call   1030 <strtok@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     116b <loc_segments+0x5b>
lea    0xeb1(%rip),%rsi
xor    %edi,%edi
call   1030 <strtok@plt>
mov    %rax,(%r14)
cmp    $0x1,%rax
mov    $0x3,%eax
sbb    $0x0,%eax
jmp    1170 <loc_segments+0x60>
xor    %eax,%eax
jmp    1170 <loc_segments+0x60>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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