#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 /*<<< orphan*/ strncmp(char *, char *, int);
int mycmp(char *s1, char *s2) {
  int l;
  l = strlen(s1) < strlen(s2) ? strlen(s1) : strlen(s2);
  if (strlen(s1) > strlen(s2)) {
    return (!1);
  } else {
    return (!strncmp(s1, s2, l));
  }
}


x86 assembly (clang, -O0):
<mycmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1163 <mycmp+0x43>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
jmp    116f <mycmp+0x4f>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    11a3 <mycmp+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <mycmp+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
mov    %r14,%rdi
cmovl  %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%ebp
jg     117e <mycmp+0x5e>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mycmp(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp slt i32 %3, %4
%6 = select i1 %5, i8* %0, i8* %1
%7 = tail call i32 @strlen(i8* %6)
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %7)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ %14, %11 ], [ 0, %2 ]
ret i32 %16
}