#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 */
unsigned int strcspn(char *, char *);
int /*<<< orphan*/ twopence_plugin_name_is_valid(char *);
char *twopence_target_split(char **target_spec_p) {
  char *plugin;
  unsigned int len;
  if (target_spec_p == NULL || (plugin = *target_spec_p) == NULL)
    return NULL;
  len = strcspn(plugin, ":");
  if (len == 0) {
    *target_spec_p = NULL;
    return plugin;
  }
  if (plugin[len] != '\0') {
    plugin[len++] = '\0';
    *target_spec_p = plugin + len;
  } else {
    *target_spec_p = NULL;
  }
  if (!twopence_plugin_name_is_valid(plugin))
    return NULL;
  return plugin;
}


x86 assembly (clang, -O0):
<twopence_target_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114c <twopence_target_split+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1159 <twopence_target_split+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11ff <twopence_target_split+0xdf>
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118e <twopence_target_split+0x6e>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <twopence_target_split+0xdf>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11cd <twopence_target_split+0xad>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%eax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d8 <twopence_target_split+0xb8>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <twopence_plugin_name_is_valid@plt>
cmp    $0x0,%eax
jne    11f7 <twopence_target_split+0xd7>
movq   $0x0,-0x8(%rbp)
jmp    11ff <twopence_target_split+0xdf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twopence_target_split>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115b <twopence_target_split+0x3b>
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %rbx,%rbx
je     115b <twopence_target_split+0x3b>
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcspn@plt>
test   %eax,%eax
je     115f <twopence_target_split+0x3f>
mov    %eax,%ecx
cmpb   $0x0,(%rbx,%rcx,1)
je     1168 <twopence_target_split+0x48>
add    $0x1,%eax
movb   $0x0,(%rbx,%rcx,1)
add    %rbx,%rax
jmp    116a <twopence_target_split+0x4a>
xor    %ebx,%ebx
jmp    117d <twopence_target_split+0x5d>
movq   $0x0,(%r14)
jmp    117d <twopence_target_split+0x5d>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1040 <twopence_plugin_name_is_valid@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmove  %rcx,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define i8* @twopence_target_split(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i32 @strcspn(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
store i8* null, i8** %0
br label %24
10: ; preds = %6
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = add i32 %7, 1
store i8 0, i8* %12
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %4, i64 %17
br label %19
19: ; preds = %10, %15
%20 = phi i8* [ %18, %15 ], [ null, %10 ]
store i8* %20, i8** %0
%21 = tail call i32 @twopence_plugin_name_is_valid(i8* %4)
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i8* null, i8* %4
br label %24
24: ; preds = %19, %1, %3, %9
%25 = phi i8* [ %4, %9 ], [ null, %3 ], [ null, %1 ], [ %23, %19 ]
ret i8* %25
}