#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 strcmp(char const *, char const *);
char *strrchr(char const *, char);
int compare_names(const void *n1arg, const void *n2arg) {
  int rslt;
  const char *n1 = (const char *)n1arg;
  const char *n2 = (const char *)n2arg;
  const char *n1a;
  const char *n2a;
  rslt = strcmp(n1 + 40, n2 + 40);
  if (rslt != 0)
    return rslt;
  n1a = strrchr(n1 + 40, ' ');
  n1a = (n1a ? n1a + 1 : n1);
  n2a = strrchr(n2 + 40, ' ');
  n2a = (n2a ? n2a + 1 : n2);
  return strcmp(n1a, n2a);
}


x86 assembly (clang, -O0):
<compare_names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x28,%rdi
mov    -0x30(%rbp),%rsi
add    $0x28,%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116d <compare_names+0x4d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <compare_names+0xe1>
mov    -0x28(%rbp),%rdi
add    $0x28,%rdi
mov    $0x20,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     119f <compare_names+0x7f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11a7 <compare_names+0x87>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x28,%rdi
mov    $0x20,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11e1 <compare_names+0xc1>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11e9 <compare_names+0xc9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_names>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x28(%rdi),%rbx
lea    0x28(%rsi),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1151 <compare_names+0x31>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %r12,%rdi
mov    $0x20,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %r14,%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcmp@plt>

LLVM IR (-O0):
define i32 @compare_names(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
store i8* %11, i8** %7
%12 = load i8*, i8** %5
store i8* %12, i8** %8
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 40
%15 = load i8*, i8** %8
%16 = getelementptr inbounds i8, i8* %15, i64 40
%17 = call i32 @strcmp(i8* %14, i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %50
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 40
%25 = call i8* @strrchr(i8* %24, i8 signext 32)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 1
br label %33
31: ; preds = %22
%32 = load i8*, i8** %7
br label %33
33: ; preds = %31, %28
%34 = phi i8* [ %30, %28 ], [ %32, %31 ]
store i8* %34, i8** %9
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i64 40
%37 = call i8* @strrchr(i8* %36, i8 signext 32)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i64 1
br label %45
43: ; preds = %33
%44 = load i8*, i8** %8
br label %45
45: ; preds = %43, %40
%46 = phi i8* [ %42, %40 ], [ %44, %43 ]
store i8* %46, i8** %10
%47 = load i8*, i8** %9
%48 = load i8*, i8** %10
%49 = call i32 @strcmp(i8* %47, i8* %48)
store i32 %49, i32* %3
br label %50
50: ; preds = %45, %20
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @compare_names(i8* %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 40
%4 = getelementptr inbounds i8, i8* %1, i64 40
%5 = tail call i32 @strcmp(i8* %3, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = tail call i8* @strrchr(i8* %3, i8 signext 32)
%9 = icmp eq i8* %8, null
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = select i1 %9, i8* %0, i8* %10
%12 = tail call i8* @strrchr(i8* %4, i8 signext 32)
%13 = icmp eq i8* %12, null
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = select i1 %13, i8* %1, i8* %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(1) %15)
br label %17
17: ; preds = %2, %7
%18 = phi i32 [ %16, %7 ], [ %5, %2 ]
ret i32 %18
}