#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
__attribute__((regparm(0))) int deputy_findnull(const void *e,
                                                unsigned int bytes) {
  int length = 0;
  switch (bytes) {
  case 1:
    do {
      char *p = (char *)e;
      while (*p != 0) {
        p++;
      }
      length = (p - (char *)e);
    } while (0);
    break;
  case 2:
    do {
      short *p = (short *)e;
      while (*p != 0) {
        p++;
      }
      length = (p - (short *)e);
    } while (0);
    break;
  case 4:
    do {
      long *p = (long *)e;
      while (*p != 0) {
        p++;
      }
      length = (p - (long *)e);
    } while (0);
    break;
  default:
    fprintf(stderr, "Invalid byte size for nullcheck.\n");
    exit(1);
  }
  return length;
}


x86 assembly (clang, -O0):
<deputy_findnull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     116c <deputy_findnull+0x4c>
jmp    114a <deputy_findnull+0x2a>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     11ad <deputy_findnull+0x8d>
jmp    115b <deputy_findnull+0x3b>
mov    -0x2c(%rbp),%eax
sub    $0x4,%eax
je     11f2 <deputy_findnull+0xd2>
jmp    1235 <deputy_findnull+0x115>
jmp    1171 <deputy_findnull+0x51>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119a <deputy_findnull+0x7a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1179 <deputy_findnull+0x59>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    1254 <deputy_findnull+0x134>
jmp    11b2 <deputy_findnull+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movswl (%rax),%eax
cmp    $0x0,%eax
je     11db <deputy_findnull+0xbb>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    11ba <deputy_findnull+0x9a>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sar    $0x1,%rax
mov    %eax,-0x10(%rbp)
jmp    1254 <deputy_findnull+0x134>
jmp    11f7 <deputy_findnull+0xd7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     121e <deputy_findnull+0xfe>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11ff <deputy_findnull+0xdf>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %eax,-0x10(%rbp)
jmp    1254 <deputy_findnull+0x134>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deputy_findnull>:
push   %rax
cmp    $0x4,%esi
je     1150 <deputy_findnull+0x30>
cmp    $0x2,%esi
je     1171 <deputy_findnull+0x51>
cmp    $0x1,%esi
jne    1191 <deputy_findnull+0x71>
mov    $0xffffffffffffffff,%rcx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rax
cmpb   $0x0,0x1(%rdi,%rcx,1)
mov    %rax,%rcx
jne    1140 <deputy_findnull+0x20>
pop    %rcx
ret
mov    $0xffffffffffffffff,%rcx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rax
cmpq   $0x0,0x8(%rdi,%rcx,8)
mov    %rax,%rcx
jne    1160 <deputy_findnull+0x40>
jmp    114e <deputy_findnull+0x2e>
mov    $0xfffffffffffffffe,%rax
nopl   0x0(%rax,%rax,1)
cmpw   $0x0,0x2(%rdi,%rax,1)
lea    0x2(%rax),%rax
jne    1180 <deputy_findnull+0x60>
sar    %rax
pop    %rcx
ret
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Invalid byte size for nullcheck.\0A\00"
define i32 @deputy_findnull(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i16*
%8 = alloca i64*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %4
switch i32 %9, label %72 [
i32 1, label %10
i32 2, label %29
i32 4, label %51
]
10: ; preds = %2
br label %11
11: ; preds = %10
%12 = load i8*, i8** %3
store i8* %12, i8** %6
br label %13
13: ; preds = %18, %11
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
br label %13
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = load i8*, i8** %3
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %5
br label %28
28: ; preds = %21
br label %76
29: ; preds = %2
br label %30
30: ; preds = %29
%31 = load i8*, i8** %3
%32 = bitcast i8* %31 to i16*
store i16* %32, i16** %7
br label %33
33: ; preds = %38, %30
%34 = load i16*, i16** %7
%35 = load i16, i16* %34
%36 = sext i16 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i16*, i16** %7
%40 = getelementptr inbounds i16, i16* %39, i32 1
store i16* %40, i16** %7
br label %33
41: ; preds = %33
%42 = load i16*, i16** %7
%43 = load i8*, i8** %3
%44 = bitcast i8* %43 to i16*
%45 = ptrtoint i16* %42 to i64
%46 = ptrtoint i16* %44 to i64
%47 = sub i64 %45, %46
%48 = sdiv exact i64 %47, 2
%49 = trunc i64 %48 to i32
store i32 %49, i32* %5
br label %50
50: ; preds = %41
br label %76
51: ; preds = %2
br label %52
52: ; preds = %51
%53 = load i8*, i8** %3
%54 = bitcast i8* %53 to i64*
store i64* %54, i64** %8
br label %55
55: ; preds = %59, %52
%56 = load i64*, i64** %8
%57 = load i64, i64* %56
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i64*, i64** %8
%61 = getelementptr inbounds i64, i64* %60, i32 1
store i64* %61, i64** %8
br label %55
62: ; preds = %55
%63 = load i64*, i64** %8
%64 = load i8*, i8** %3
%65 = bitcast i8* %64 to i64*
%66 = ptrtoint i64* %63 to i64
%67 = ptrtoint i64* %65 to i64
%68 = sub i64 %66, %67
%69 = sdiv exact i64 %68, 8
%70 = trunc i64 %69 to i32
store i32 %70, i32* %5
br label %71
71: ; preds = %62
br label %76
72: ; preds = %2
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %71, %50, %28
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Invalid byte size for nullcheck.\0A\00"
define i32 @deputy_findnull(i8* %0, i32 %1) {
switch i32 %1, label %36 [
i32 1, label %3
i32 2, label %12
i32 4, label %24
]
3: ; preds = %2, %3
%4 = phi i8* [ %7, %3 ], [ %0, %2 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
br label %40
12: ; preds = %2
%13 = bitcast i8* %0 to i16*
br label %14
14: ; preds = %14, %12
%15 = phi i16* [ %13, %12 ], [ %18, %14 ]
%16 = load i16, i16* %15
%17 = icmp eq i16 %16, 0
%18 = getelementptr inbounds i16, i16* %15, i64 1
br i1 %17, label %19, label %14
19: ; preds = %14
%20 = ptrtoint i16* %15 to i64
%21 = ptrtoint i8* %0 to i64
%22 = sub i64 %20, %21
%23 = ashr exact i64 %22, 1
br label %40
24: ; preds = %2
%25 = bitcast i8* %0 to i64*
br label %26
26: ; preds = %26, %24
%27 = phi i64* [ %25, %24 ], [ %30, %26 ]
%28 = load i64, i64* %27
%29 = icmp eq i64 %28, 0
%30 = getelementptr inbounds i64, i64* %27, i64 1
br i1 %29, label %31, label %26
31: ; preds = %26
%32 = ptrtoint i64* %27 to i64
%33 = ptrtoint i8* %0 to i64
%34 = sub i64 %32, %33
%35 = lshr exact i64 %34, 3
br label %40
36: ; preds = %2
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %31, %19, %8
%41 = phi i64 [ %35, %31 ], [ %23, %19 ], [ %11, %8 ]
%42 = trunc i64 %41 to i32
ret i32 %42
}