#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 strncmp(char const *, char const *, int);
char *strpbrk(char const *, char *);
int MDtoolcmp(const char *tool, const char *s, int slen) {
  char *t;
  int toollen;
  t = strpbrk(tool, " \n");
  toollen = t - tool;
  if ((t == 0) || (toollen != slen)) {
    return -1;
  }
  return strncmp(tool, s, slen);
}


x86 assembly (clang, -O0):
<MDtoolcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     116c <MDtoolcmp+0x4c>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1178 <MDtoolcmp+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <MDtoolcmp+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MDtoolcmp>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecd(%rip),%rsi
call   1040 <strpbrk@plt>
test   %rax,%rax
je     1154 <MDtoolcmp+0x34>
sub    %ebx,%eax
cmp    %ebp,%eax
jne    1154 <MDtoolcmp+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strncmp@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" \0A\00"
define i32 @MDtoolcmp(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strpbrk(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i8* %4, null
%6 = ptrtoint i8* %4 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = icmp eq i32 %9, %2
%11 = select i1 %5, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %2)
br label %14
14: ; preds = %3, %12
%15 = phi i32 [ %13, %12 ], [ -1, %3 ]
ret i32 %15
}