#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 *);
scalar_t__ strncmp(char *, char *, int);
int mystr_eq(char *s1, char *s2) {
  int len1, len2;
  if ((s1 == NULL) || (s2 == NULL))
    return 0;
  len1 = strlen(s1);
  len2 = strlen(s2);
  if (len1 != len2)
    return 0;
  if (strncmp(s1, s2, len1) == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<mystr_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <mystr_eq+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <mystr_eq+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11af <mystr_eq+0x8f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1182 <mystr_eq+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11af <mystr_eq+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a8 <mystr_eq+0x88>
movl   $0x1,-0x4(%rbp)
jmp    11af <mystr_eq+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mystr_eq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     1167 <mystr_eq+0x47>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1167 <mystr_eq+0x47>
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r15d
jne    1167 <mystr_eq+0x47>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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