#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 *);
int strncmp(char *, char *, int);
int cmpWord(const void *a, const void *b) {
  char *wa = (char *)a;
  char *wb = (char *)b;
  int len = strlen(wa) - strlen(wb);
  int cmp = strncmp(wa, wb, (len > 0 ? strlen(wb) : strlen(wa)));
  return cmp == 0 ? len : cmp;
}


x86 assembly (clang, -O0):
<cmpWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    118a <cmpWord+0x6a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
jmp    1196 <cmpWord+0x76>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11be <cmpWord+0x9e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    11c4 <cmpWord+0xa4>
mov    -0x28(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpWord>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
test   %ebp,%ebp
mov    %rbx,%rdi
cmovg  %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
cmove  %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @cmpWord(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = sub nsw i32 %3, %4
%6 = icmp sgt i32 %5, 0
%7 = select i1 %6, i8* %1, i8* %0
%8 = tail call i32 @strlen(i8* %7)
%9 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %8)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 %5, i32 %9
ret i32 %11
}