#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*/ __ESBMC_assert(int, char *);
size_t __ESBMC_buffer_size(char const *);
scalar_t__ __ESBMC_is_zero_string(char const *);
int strncmp_strabs(const char *s1, const char *s2, size_t n) {
  if (s1 != 0 && s1 == s2)
    return 0;
  __ESBMC_assert(__ESBMC_is_zero_string(s1) || __ESBMC_buffer_size(s1) >= n,
                 "strncmp zero-termination of 1st argument");
  __ESBMC_assert(__ESBMC_is_zero_string(s1) || __ESBMC_buffer_size(s2) >= n,
                 "strncmp zero-termination of 2nd argument");
  return 0;
}


x86 assembly (clang, -O0):
<strncmp_strabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1169 <strncmp_strabs+0x39>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1169 <strncmp_strabs+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <strncmp_strabs+0xc4>
mov    -0x10(%rbp),%rdi
call   1040 <__ESBMC_is_zero_string@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    1197 <strncmp_strabs+0x67>
mov    -0x10(%rbp),%rdi
call   1050 <__ESBMC_buffer_size@plt>
cmp    -0x20(%rbp),%rax
setae  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
lea    0xe5a(%rip),%rsi
call   1030 <__ESBMC_assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <__ESBMC_is_zero_string@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x22(%rbp)
jne    11d9 <strncmp_strabs+0xa9>
mov    -0x18(%rbp),%rdi
call   1050 <__ESBMC_buffer_size@plt>
cmp    -0x20(%rbp),%rax
setae  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
lea    0xe41(%rip),%rsi
call   1030 <__ESBMC_assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncmp_strabs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
test   %rdi,%rdi
je     114a <strncmp_strabs+0x1a>
cmp    %rbx,%rbp
je     11ad <strncmp_strabs+0x7d>
mov    %rbp,%rdi
call   1040 <__ESBMC_is_zero_string@plt>
mov    $0x1,%r15d
mov    $0x1,%edi
test   %rax,%rax
jne    1173 <strncmp_strabs+0x43>
mov    %rbp,%rdi
call   1050 <__ESBMC_buffer_size@plt>
xor    %edi,%edi
cmp    %r14,%rax
setae  %dil
lea    0xe86(%rip),%rsi
call   1030 <__ESBMC_assert@plt>
mov    %rbp,%rdi
call   1040 <__ESBMC_is_zero_string@plt>
test   %rax,%rax
jne    119e <strncmp_strabs+0x6e>
mov    %rbx,%rdi
call   1050 <__ESBMC_buffer_size@plt>
xor    %r15d,%r15d
cmp    %r14,%rax
setae  %r15b
lea    0xe84(%rip),%rsi
mov    %r15d,%edi
call   1030 <__ESBMC_assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"strncmp zero-termination of 1st argument\00"
@.str.1 = [41 x i8] c"strncmp zero-termination of 2nd argument\00"
define i32 @strncmp_strabs(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 0, i32* %4
br label %40
15: ; preds = %10, %3
%16 = load i8*, i8** %5
%17 = call i64 @__ESBMC_is_zero_string(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i64 @__ESBMC_buffer_size(i8* %20)
%22 = load i64, i64* %7
%23 = icmp uge i64 %21, %22
br label %24
24: ; preds = %19, %15
%25 = phi i1 [ true, %15 ], [ %23, %19 ]
%26 = zext i1 %25 to i32
%27 = call i32 @__ESBMC_assert(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %5
%29 = call i64 @__ESBMC_is_zero_string(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %24
%32 = load i8*, i8** %6
%33 = call i64 @__ESBMC_buffer_size(i8* %32)
%34 = load i64, i64* %7
%35 = icmp uge i64 %33, %34
br label %36
36: ; preds = %31, %24
%37 = phi i1 [ true, %24 ], [ %35, %31 ]
%38 = zext i1 %37 to i32
%39 = call i32 @__ESBMC_assert(i32 %38, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %40
40: ; preds = %36, %14
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [41 x i8] c"strncmp zero-termination of 1st argument\00"
@.str.1 = [41 x i8] c"strncmp zero-termination of 2nd argument\00"
define i32 @strncmp_strabs(i8* %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp eq i8* %0, %1
%6 = and i1 %4, %5
br i1 %6, label %26, label %7
7: ; preds = %3
%8 = tail call i64 @__ESBMC_is_zero_string(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i64 @__ESBMC_buffer_size(i8* %0)
%12 = icmp uge i64 %11, %2
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ 1, %7 ], [ %13, %10 ]
%16 = tail call i32 @__ESBMC_assert(i32 %15, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%17 = tail call i64 @__ESBMC_is_zero_string(i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i64 @__ESBMC_buffer_size(i8* %1)
%21 = icmp uge i64 %20, %2
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %14
%24 = phi i32 [ 1, %14 ], [ %22, %19 ]
%25 = tail call i32 @__ESBMC_assert(i32 %24, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %3, %23
ret i32 0
}