#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 asn1_string_st {
  int length;
  char *data;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ stderr;
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int asn1_compare_str(int test_no, struct asn1_string_st *asn1str,
                     const char *str) {
  int length = strlen(str);
  if (asn1str->length != length) {
    fprintf(stderr,
            "FAIL: test %i - string lengths differ "
            "(%i != %i)\n",
            test_no, asn1str->length, length);
    return (1);
  }
  if (strncmp(asn1str->data, str, length) != 0) {
    fprintf(stderr,
            "FAIL: test %i - strings differ "
            "('%s' != '%s')\n",
            test_no, asn1str->data, str);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<asn1_compare_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
je     118e <asn1_compare_str+0x5e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <asn1_compare_str+0xb5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11de <asn1_compare_str+0xae>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%r8
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <asn1_compare_str+0xb5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_compare_str>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    0x0(%rbp),%ecx
cmp    %eax,%ecx
jne    1182 <asn1_compare_str+0x52>
mov    0x8(%rbp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a6 <asn1_compare_str+0x76>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rcx
lea    0xebf(%rip),%rsi
mov    %r14d,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    119f <asn1_compare_str+0x6f>
mov    0x2e57(%rip),%rdx
mov    (%rdx),%edi
lea    0xe6e(%rip),%rsi
mov    %r14d,%edx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11a8 <asn1_compare_str+0x78>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.asn1_string_st = type { i32, i8* }
@stderr = global i32 0
@.str = [50 x i8] c"FAIL: test %i - string lengths differ (%i != %i)\0A\00"
@.str.1 = [47 x i8] c"FAIL: test %i - strings differ ('%s' != '%s')\0A\00"
define i32 @asn1_compare_str(i32 %0, %struct.asn1_string_st* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.asn1_string_st*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store %struct.asn1_string_st* %1, %struct.asn1_string_st** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load %struct.asn1_string_st*, %struct.asn1_string_st** %6
%12 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* %8
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* %5
%19 = load %struct.asn1_string_st*, %struct.asn1_string_st** %6
%20 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* %8
%23 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %21, i32 %22)
store i32 1, i32* %4
br label %41
24: ; preds = %3
%25 = load %struct.asn1_string_st*, %struct.asn1_string_st** %6
%26 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %25, i32 0, i32 1
%27 = load i8*, i8** %26
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = call i64 @strncmp(i8* %27, i8* %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = load i32, i32* %5
%35 = load %struct.asn1_string_st*, %struct.asn1_string_st** %6
%36 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %35, i32 0, i32 1
%37 = load i8*, i8** %36
%38 = load i8*, i8** %7
%39 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* %37, i8* %38)
store i32 1, i32* %4
br label %41
40: ; preds = %24
store i32 0, i32* %4
br label %41
41: ; preds = %40, %32, %16
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.asn1_string_st = type { i32, i8* }
@stderr = global i32 0
@.str = [50 x i8] c"FAIL: test %i - string lengths differ (%i != %i)\0A\00"
@.str.1 = [47 x i8] c"FAIL: test %i - strings differ ('%s' != '%s')\0A\00"
define i32 @asn1_compare_str(i32 %0, %struct.asn1_string_st* nocapture %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, %4
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %6, i32 %4)
br label %20
11: ; preds = %3
%12 = getelementptr inbounds %struct.asn1_string_st, %struct.asn1_string_st* %1, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strncmp(i8* %13, i8* %2, i32 %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %18, i8* %2)
br label %20
20: ; preds = %11, %16, %8
%21 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 0, %11 ]
ret i32 %21
}