#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 /*<<< orphan*/ strlen(char *);
scalar_t__ xstrncasecmp(char *, char *, int /*<<< orphan*/);
int test_xstrncasecmp(void) {
  char *s0 = "test";
  char *s1 = "test2";
  char *s2 = "Test";
  if (xstrncasecmp(s0, s1, strlen(s0)) != 0)
    return -1;
  if (xstrncasecmp(s1, s2, strlen(s1)) == 0)
    return -1;
  if (xstrncasecmp(s0, s2, strlen(s0)) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<test_xstrncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
cmp    $0x0,%rax
je     1187 <test_xstrncasecmp+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <test_xstrncasecmp+0xea>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
cmp    $0x0,%rax
jne    11c5 <test_xstrncasecmp+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <test_xstrncasecmp+0xea>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
cmp    $0x0,%rax
je     1203 <test_xstrncasecmp+0xe3>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <test_xstrncasecmp+0xea>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_xstrncasecmp>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1198 <test_xstrncasecmp+0x78>
lea    0xeb0(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
test   %rax,%rax
je     1198 <test_xstrncasecmp+0x78>
lea    0xe86(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <xstrncasecmp@plt>
neg    %rax
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [6 x i8] c"test2\00"
@.str.2 = [5 x i8] c"Test\00"
define i32 @test_xstrncasecmp() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %2
%6 = load i8*, i8** %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = call i64 @xstrncasecmp(i8* %5, i8* %6, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 -1, i32* %1
br label %29
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i64 @xstrncasecmp(i8* %13, i8* %14, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %1
br label %29
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = call i32 @strlen(i8* %23)
%25 = call i64 @xstrncasecmp(i8* %21, i8* %22, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 -1, i32* %1
br label %29
28: ; preds = %20
store i32 0, i32* %1
br label %29
29: ; preds = %28, %27, %19, %11
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [6 x i8] c"test2\00"
@.str.2 = [5 x i8] c"Test\00"
define i32 @test_xstrncasecmp() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @xstrncasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %0
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 @xstrncasecmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = tail call i64 @xstrncasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp ne i64 %10, 0
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %8, %4, %0
%14 = phi i32 [ -1, %0 ], [ -1, %4 ], [ %12, %8 ]
ret i32 %14
}