#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 */
char *macsearch(unsigned char const *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_partial_match() {
  const unsigned char mac[6] = {0xb8, 0x27, 0xeb, 0x9a, 0x47, 0x11};
  const char *result = NULL;
  if (NULL == (result = macsearch(mac, 6))) {
    return 1;
  }
  printf("Found non NULL value: %s\n", result);
  if (NULL != (result = macsearch(mac, 2))) {
    printf("Found non NULL value: %s\n", result);
    return 1;
  }
  printf("Found nothing as expected\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_partial_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed2(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xecc(%rip),%ax
mov    %ax,-0x6(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0xa(%rbp),%rdi
mov    $0x6,%esi
call   1040 <macsearch@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1170 <test_partial_match+0x50>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <test_partial_match+0xb5>
mov    -0x18(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa(%rbp),%rdi
mov    $0x2,%esi
call   1040 <macsearch@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11c0 <test_partial_match+0xa0>
mov    -0x18(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <test_partial_match+0xb5>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_partial_match>:
push   %rbx
sub    $0x10,%rsp
movw   $0x1147,0xc(%rsp)
movl   $0x9aeb27b8,0x8(%rsp)
9a
lea    0x8(%rsp),%rdi
mov    $0x6,%esi
call   1050 <macsearch@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11a3 <test_partial_match+0x73>
lea    0xea2(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1050 <macsearch@plt>
test   %rax,%rax
je     1195 <test_partial_match+0x65>
lea    0xe7d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a3 <test_partial_match+0x73>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_partial_match.mac = [6 x i8] c"\B8'\EB\9AG\11"
@.str = [26 x i8] c"Found non NULL value: %s\0A\00"
@.str.1 = [27 x i8] c"Found nothing as expected\0A\00"
define i32 @test_partial_match() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca i8*
%4 = bitcast [6 x i8]* %2 to i8*
store i8* null, i8** %3
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = call i8* @macsearch(i8* %5, i32 6)
store i8* %6, i8** %3
%7 = icmp eq i8* null, %6
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %20
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%13 = call i8* @macsearch(i8* %12, i32 2)
store i8* %13, i8** %3
%14 = icmp ne i8* null, %13
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %1
br label %20
18: ; preds = %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %20
20: ; preds = %18, %15, %8
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@__const.test_partial_match.mac = [6 x i8] c"\B8'\EB\9AG\11"
@.str = [26 x i8] c"Found non NULL value: %s\0A\00"
@str = [26 x i8] c"Found nothing as expected\00"
define i32 @test_partial_match() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = call i8* @macsearch(i8* %2, i32 6)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = call i8* @macsearch(i8* %2, i32 2)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %13
11: ; preds = %5
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %0, %11, %9
%14 = phi i32 [ 1, %9 ], [ 0, %11 ], [ 1, %0 ]
ret i32 %14
}