#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 /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char const *);
char *strtok(char *, char *);
int is_ethlink(const char *link, const int length) {
  int rc = -1;
  char *tmp = strdup(link);
  char *token = strtok(tmp, ":");
  while (token != NULL) {
    if (strcmp(token, "tap") == 0) {
      rc = 0;
      break;
    }
    token = strtok(NULL, ":");
  }
  free(token);
  return rc;
}


x86 assembly (clang, -O0):
<is_ethlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c1 <is_ethlink+0x81>
mov    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a8 <is_ethlink+0x68>
movl   $0x0,-0x10(%rbp)
jmp    11c1 <is_ethlink+0x81>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1177 <is_ethlink+0x37>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ethlink>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1060 <strdup@plt>
lea    0xead(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11a2 <is_ethlink+0x62>
mov    %rax,%rbx
lea    0xe92(%rip),%rbp
lea    0xe89(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a6 <is_ethlink+0x66>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <is_ethlink+0x40>
xor    %ebx,%ebx
jmp    11a9 <is_ethlink+0x69>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [4 x i8] c"tap\00"
define i32 @is_ethlink(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%8 = load i8*, i8** %3
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %6
%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))
store i8* %11, i8** %7
br label %12
12: ; preds = %20, %2
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8*, i8** %7
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %5
br label %22
20: ; preds = %15
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %7
br label %12
22: ; preds = %19, %12
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
%25 = load i32, i32* %5
ret i32 %25
}

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