#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*/ assert(char const *);
int strncmp(char const *, char const *, size_t);
int partial_strcmp(const char *s1, size_t len, const char *s2) {
  assert(s1);
  if (s2 == NULL)
    return len != 0;
  int r;
  if ((r = strncmp(s1, s2, len)) != 0)
    return r;
  return s2[len] != '\0';
}


x86 assembly (clang, -O0):
<partial_strcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
jne    115d <partial_strcmp+0x3d>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <partial_strcmp+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1185 <partial_strcmp+0x65>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <partial_strcmp+0x7f>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partial_strcmp>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <assert@plt>
test   %r15,%r15
je     1153 <partial_strcmp+0x33>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    115b <partial_strcmp+0x3b>
xor    %eax,%eax
cmpb   $0x0,(%r15,%r14,1)
jmp    1158 <partial_strcmp+0x38>
xor    %eax,%eax
test   %r14,%r14
setne  %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @partial_strcmp(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 0
%16 = zext i1 %15 to i32
store i32 %16, i32* %4
br label %33
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %7
%20 = load i64, i64* %6
%21 = call i32 @strncmp(i8* %18, i8* %19, i64 %20)
store i32 %21, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %33
25: ; preds = %17
%26 = load i8*, i8** %7
%27 = load i64, i64* %6
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i32
store i32 %32, i32* %4
br label %33
33: ; preds = %25, %23, %13
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @partial_strcmp(i8* %0, i64 %1, i8* %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = icmp eq i8* %2, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = icmp ne i64 %1, 0
%8 = zext i1 %7 to i32
br label %17
9: ; preds = %3
%10 = tail call i32 @strncmp(i8* %0, i8* %2, i64 %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %2, i64 %1
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %12, %9, %6
%18 = phi i32 [ %8, %6 ], [ %16, %12 ], [ %10, %9 ]
ret i32 %18
}