#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int liw_strncmp(char const *, char const *, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int strncmp(char const *, char const *, size_t);
void test_ncmp(const char *first, const char *second) {
  size_t len;
  int std_ret, liw_ret;
  if (strlen(first) < strlen(second))
    len = strlen(second);
  else
    len = strlen(first);
  std_ret = strncmp(first, second, len);
  liw_ret = liw_strncmp(first, second, len);
  if ((std_ret < 0 && liw_ret >= 0) || (std_ret > 0 && liw_ret <= 0) ||
      (std_ret == 0 && liw_ret != 0)) {
    fprintf(stderr, "liw_strncmp failed, <%s> and <%s>\n", first, second);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<test_ncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    1198 <test_ncmp+0x48>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
jmp    11a5 <test_ncmp+0x55>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <liw_strncmp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e1 <test_ncmp+0x91>
cmpl   $0x0,-0x20(%rbp)
jge    1209 <test_ncmp+0xb9>
cmpl   $0x0,-0x1c(%rbp)
jle    11f5 <test_ncmp+0xa5>
cmpl   $0x0,-0x20(%rbp)
jle    1209 <test_ncmp+0xb9>
cmpl   $0x0,-0x1c(%rbp)
jne    1234 <test_ncmp+0xe4>
cmpl   $0x0,-0x20(%rbp)
je     1234 <test_ncmp+0xe4>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xddf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ncmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
cmovb  %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncmp@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <liw_strncmp@plt>
test   %ebp,%ebp
jns    119a <test_ncmp+0x4a>
test   %eax,%eax
jns    11b5 <test_ncmp+0x65>
test   %ebp,%ebp
jle    11a2 <test_ncmp+0x52>
test   %eax,%eax
jle    11b5 <test_ncmp+0x65>
test   %ebp,%ebp
jne    11aa <test_ncmp+0x5a>
test   %eax,%eax
jne    11b5 <test_ncmp+0x65>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <fprintf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"liw_strncmp failed, <%s> and <%s>\0A\00"
@EXIT_FAILURE = global i32 0
define void @test_ncmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %5
br label %19
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %5
br label %19
19: ; preds = %16, %13
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = call i32 @strncmp(i8* %20, i8* %21, i64 %22)
store i32 %23, i32* %6
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = load i64, i64* %5
%27 = call i32 @liw_strncmp(i8* %24, i8* %25, i64 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = load i32, i32* %7
%32 = icmp sge i32 %31, 0
br i1 %32, label %45, label %33
33: ; preds = %30, %19
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %7
%38 = icmp sle i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36, %33
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %42, %36, %30
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = load i8*, i8** %4
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %47, i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42, %39
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"liw_strncmp failed, <%s> and <%s>\0A\00"
@EXIT_FAILURE = global i32 0
define void @test_ncmp(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %3, %4
%6 = select i1 %5, i64 %4, i64 %3
%7 = tail call i32 @strncmp(i8* %0, i8* %1, i64 %6)
%8 = tail call i32 @liw_strncmp(i8* %0, i8* %1, i64 %6)
%9 = icmp slt i32 %7, 0
%10 = icmp sgt i32 %8, -1
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = icmp sgt i32 %7, 0
%14 = icmp slt i32 %8, 1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = icmp eq i32 %7, 0
%18 = icmp ne i32 %8, 0
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %20, label %25
20: ; preds = %16, %12, %2
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
ret void
}