#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 */
struct nlattr {
  int dummy;
};

/* Variables and functions */
int memcmp(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ nla_data(struct nlattr const *);
int nla_len(struct nlattr const *);
int strlen(char const *);
int nla_strcmp(const struct nlattr *nla, const char *str) {
  int len = strlen(str) + 1;
  int d = nla_len(nla) - len;
  if (d == 0)
    d = memcmp(nla_data(nla), str, len);
  return d;
}


x86 assembly (clang, -O0):
<nla_strcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nla_len@plt>
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1192 <nla_strcmp+0x52>
mov    -0x8(%rbp),%rdi
call   1060 <nla_data@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcmp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nla_strcmp>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <nla_len@plt>
sub    %ebp,%eax
je     1168 <nla_strcmp+0x28>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1060 <nla_data@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <memcmp@plt>

LLVM IR (-O0):
%struct.nlattr = type { i32 }
define i32 @nla_strcmp(%struct.nlattr* %0, i8* %1) {
%3 = alloca %struct.nlattr*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store %struct.nlattr* %0, %struct.nlattr** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load %struct.nlattr*, %struct.nlattr** %3
%11 = call i32 @nla_len(%struct.nlattr* %10)
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load %struct.nlattr*, %struct.nlattr** %3
%18 = call i32 @nla_data(%struct.nlattr* %17)
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = call i32 @memcmp(i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %6
br label %22
22: ; preds = %16, %2
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
%struct.nlattr = type { i32 }
define i32 @nla_strcmp(%struct.nlattr* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = tail call i32 @nla_len(%struct.nlattr* %0)
%6 = sub nsw i32 %5, %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @nla_data(%struct.nlattr* %0)
%10 = tail call i32 @memcmp(i32 %9, i8* %1, i32 %4)
br label %11
11: ; preds = %8, %2
%12 = phi i32 [ %10, %8 ], [ %6, %2 ]
ret i32 %12
}