#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*/ nis_name;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ strdup(char *);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int /*<<< orphan*/ strndup(char *, int);
nis_name searchXYX(char *str, const char *what) {
  assert(strlen(what) == 6);
  assert(strncmp(str, what, 6) == 0);
  str += 6;
  int i = 0;
  while (str[i] != '\0' && str[i] != ':')
    ++i;
  if (i == 0)
    return strdup("");
  return strndup(str, i);
}


x86 assembly (clang, -O0):
<searchXYX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     11de <searchXYX+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11ee <searchXYX+0x9e>
jmp    11fc <searchXYX+0xac>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <searchXYX+0x5f>
cmpl   $0x0,-0x1c(%rbp)
jne    121a <searchXYX+0xca>
lea    0xdf3(%rip),%rdi
call   1070 <strdup@plt>
mov    %eax,-0x4(%rbp)
jmp    1229 <searchXYX+0xd9>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <strndup@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchXYX>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    $0x6,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
add    $0x6,%rbx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rsi,1),%eax
test   %al,%al
je     11b2 <searchXYX+0x62>
cmp    $0x3a,%al
je     11b2 <searchXYX+0x62>
add    $0x1,%rsi
jmp    11a0 <searchXYX+0x50>
test   %esi,%esi
je     11c5 <searchXYX+0x75>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strndup@plt>
lea    0xe34(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @searchXYX(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
%9 = icmp eq i32 %8, 6
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i64 @strncmp(i8* %12, i8* %13, i32 6)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 6
store i8* %19, i8** %4
store i32 0, i32* %6
br label %20
20: ; preds = %38, %2
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 58
br label %36
36: ; preds = %28, %20
%37 = phi i1 [ false, %20 ], [ %35, %28 ]
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %20
41: ; preds = %36
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %45, i32* %3
br label %50
46: ; preds = %41
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = call i32 @strndup(i8* %47, i32 %48)
store i32 %49, i32* %3
br label %50
50: ; preds = %46, %44
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @searchXYX(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp eq i32 %3, 6
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i64 @strncmp(i8* %0, i8* %1, i32 6)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 6
br label %12
12: ; preds = %16, %2
%13 = phi i64 [ %17, %16 ], [ 0, %2 ]
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 0, label %18
i8 58, label %18
]
16: ; preds = %12
%17 = add nuw i64 %13, 1
br label %12
18: ; preds = %12, %12
%19 = trunc i64 %13 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = tail call i32 @strndup(i8* %11, i32 %19)
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
ret i32 %26
}