#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 */
scalar_t__ memcmp(unsigned char const *, char const *, int);
int strlen(char const *);
int counted_string_equal(unsigned const char *a, int a_len, const char *b,
                         int b_len) {
  if (a_len < 0)
    a_len = strlen((const char *)a);
  if (b_len < 0)
    b_len = strlen(b);
  return a_len == b_len && memcmp(a, b, a_len) == 0;
}


x86 assembly (clang, -O0):
<counted_string_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114c <counted_string_equal+0x2c>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1162 <counted_string_equal+0x42>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jne    118d <counted_string_equal+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<counted_string_equal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
test   %esi,%esi
js     1162 <counted_string_equal+0x42>
test   %ebx,%ebx
js     1170 <counted_string_equal+0x50>
xor    %eax,%eax
cmp    %ebx,%ebp
jne    1157 <counted_string_equal+0x37>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %ebx,%ebx
jns    1139 <counted_string_equal+0x19>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
jmp    1139 <counted_string_equal+0x19>

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

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