#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 strcspn(char *, char const *);
int strncmp(char *, char *, int);
int wordcmp(char *s1, char *s2, const char *delim) {
  int n1 = strcspn(s1, delim);
  int n2 = strcspn(s2, delim);
  if (n1 < n2)
    return -1;
  else if (n1 > n2)
    return 1;
  return strncmp(s1, s2, n1);
}


x86 assembly (clang, -O0):
<wordcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    116c <wordcmp+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <wordcmp+0x7c>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1184 <wordcmp+0x64>
movl   $0x1,-0x4(%rbp)
jmp    119c <wordcmp+0x7c>
jmp    1189 <wordcmp+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wordcmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rsi
call   1040 <strcspn@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%ebp
jl     1157 <wordcmp+0x37>
mov    $0x1,%eax
jle    1162 <wordcmp+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncmp@plt>

LLVM IR (-O0):
define i32 @wordcmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %7
%12 = call i32 @strcspn(i8* %10, i8* %11)
store i32 %12, i32* %8
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = call i32 @strcspn(i8* %13, i8* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %31
20: ; preds = %3
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %4
br label %31
25: ; preds = %20
br label %26
26: ; preds = %25
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = load i32, i32* %8
%30 = call i32 @strncmp(i8* %27, i8* %28, i32 %29)
store i32 %30, i32* %4
br label %31
31: ; preds = %26, %24, %19
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @wordcmp(i8* %0, i8* %1, i8* nocapture %2) {
%4 = tail call i32 @strcspn(i8* %0, i8* %2)
%5 = tail call i32 @strcspn(i8* %1, i8* %2)
%6 = icmp slt i32 %4, %5
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = icmp sgt i32 %4, %5
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %4)
br label %11
11: ; preds = %7, %3, %9
%12 = phi i32 [ %10, %9 ], [ -1, %3 ], [ 1, %7 ]
ret i32 %12
}