#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 *, char *);
int strlen(char *);
int cmp_strlen(const void *e1, const void *e2) {
  char **s1, **s2;
  int c;
  s1 = (char **)e1;
  s2 = (char **)e2;
  c = strlen(*s2) - strlen(*s1);
  if (c)
    return c;
  return strcmp(*s1, *s2);
}


x86 assembly (clang, -O0):
<cmp_strlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     117a <cmp_strlen+0x5a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <cmp_strlen+0x70>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_strlen>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
je     1147 <cmp_strlen+0x27>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rdi
mov    (%r14),%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strcmp@plt>

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

LLVM IR (-O2):
define i32 @cmp_strlen(i8* nocapture %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to i8**
%4 = bitcast i8* %1 to i8**
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* %5)
%7 = load i8*, i8** %3
%8 = tail call i32 @strlen(i8* %7)
%9 = sub nsw i32 %6, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(1) %13)
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ %14, %11 ], [ %9, %2 ]
ret i32 %16
}