#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 strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int /*<<< orphan*/ strtok_r(char *, char *, char **);
int startswith(char *str, const char *test, char **strtok_data) {
  int len = strlen(test);
  if ((strncmp(str, test, len) == 0) && (str[len] == ':')) {
    strtok_r(str, ":", strtok_data);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<startswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119f <startswith+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    119f <startswith+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe72(%rip),%rsi
call   1050 <strtok_r@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <startswith+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startswith>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1182 <startswith+0x52>
movslq %ebp,%rcx
cmpb   $0x3a,(%r15,%rcx,1)
jne    1182 <startswith+0x52>
lea    0xe8e(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define i32 @startswith(i8* %0, i8* %1, i8** %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 58
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
br label %14
14: ; preds = %3, %7, %12
%15 = phi i32 [ 1, %12 ], [ 0, %7 ], [ 0, %3 ]
ret i32 %15
}