#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 *strchr(char const *, char);
int extract_zone_name(char **startidx, const char *cmd) {
  char *idx = NULL;
  idx = strchr(cmd, '/');
  if (idx == NULL)
    return 0;
  idx = strchr(idx + 1, '/');
  if (idx == NULL)
    return 0;
  *startidx = idx + 1;
  idx = strchr(*startidx, '/');
  if (idx == NULL)
    return 0;
  return idx - *startidx;
}


x86 assembly (clang, -O0):
<extract_zone_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1151 <extract_zone_name+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11ca <extract_zone_name+0xba>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117e <extract_zone_name+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    11ca <extract_zone_name+0xba>
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <extract_zone_name+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    11ca <extract_zone_name+0xba>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_zone_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1161 <extract_zone_name+0x51>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1161 <extract_zone_name+0x51>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,(%r14)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1161 <extract_zone_name+0x51>
sub    %ebx,%eax
mov    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extract_zone_name(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %5
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %37
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i8* @strchr(i8* %14, i8 signext 47)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 0, i32* %3
br label %37
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8**, i8*** %4
store i8* %21, i8** %22
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %19
store i32 0, i32* %3
br label %37
29: ; preds = %19
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = ptrtoint i8* %30 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %3
br label %37
37: ; preds = %29, %28, %18, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @extract_zone_name(i8** nocapture writeonly %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i8* @strchr(i8* %6, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %10, i8** %0
%11 = tail call i8* @strchr(i8* %10, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %10 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
br label %18
18: ; preds = %9, %5, %2, %13
%19 = phi i32 [ %17, %13 ], [ 0, %2 ], [ 0, %5 ], [ 0, %9 ]
ret i32 %19
}