#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *check_zero(unsigned char *buf, int size) {
  unsigned char *p;
  p = buf;
  while (size > 0) {
    if (*buf != 0) {
      fprintf(stderr, "non zero buffer at buf[%d] => 0x%02x,%02x,%02x,%02x\n",
              buf - p, (unsigned int)buf[0],
              size > 1 ? (unsigned int)buf[1] : 0,
              size > 2 ? (unsigned int)buf[2] : 0,
              size > 3 ? (unsigned int)buf[3] : 0);
      fprintf(stderr, "buf %p, p %p\n", buf, p);
      return buf;
    }
    buf++;
    size--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    124a <check_zero+0x13a>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1230 <check_zero+0x120>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1180 <check_zero+0x70>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    118a <check_zero+0x7a>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    118a <check_zero+0x7a>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    11aa <check_zero+0x9a>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    11b4 <check_zero+0xa4>
xor    %eax,%eax
mov    %eax,-0x40(%rbp)
jmp    11b4 <check_zero+0xa4>
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x3,-0x14(%rbp)
jle    11d4 <check_zero+0xc4>
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    11de <check_zero+0xce>
xor    %eax,%eax
mov    %eax,-0x48(%rbp)
jmp    11de <check_zero+0xce>
mov    -0x44(%rbp),%r9d
mov    -0x3c(%rbp),%r8d
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%eax
lea    0xe06(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1252 <check_zero+0x142>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <check_zero+0x17>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_zero>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1148 <check_zero+0x38>
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rdx,1),%ecx
test   %ecx,%ecx
jne    114d <check_zero+0x3d>
lea    -0x1(%rsi),%eax
add    $0x1,%rdx
cmp    $0x1,%esi
mov    %eax,%esi
jg     1130 <check_zero+0x20>
jmp    11be <check_zero+0xae>
xor    %r14d,%r14d
jmp    11be <check_zero+0xae>
mov    0x2e8c(%rip),%r15
mov    (%r15),%edi
lea    (%rbx,%rdx,1),%r14
xor    %r9d,%r9d
mov    $0x0,%r8d
mov    $0x0,%eax
cmp    $0x2,%esi
jb     118e <check_zero+0x7e>
mov    0x1(%rbx,%rdx,1),%r8b
xor    %eax,%eax
cmp    $0x2,%esi
jne    117f <check_zero+0x6f>
xor    %r9d,%r9d
jmp    118e <check_zero+0x7e>
mov    0x2(%rbx,%rdx,1),%r9b
cmp    $0x4,%esi
jb     118e <check_zero+0x7e>
movzbl 0x3(%rbx,%rdx,1),%eax
movzbl %r8b,%r8d
movzbl %r9b,%r9d
mov    %eax,(%rsp)
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xe84(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"non zero buffer at buf[%d] => 0x%02x,%02x,%02x,%02x\0A\00"
@.str.1 = [14 x i8] c"buf %p, p %p\0A\00"
define i8* @check_zero(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
br label %8
8: ; preds = %63, %2
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %68
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %63
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = load i8*, i8** %6
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %34
29: ; preds = %16
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
br label %35
34: ; preds = %16
br label %35
35: ; preds = %34, %29
%36 = phi i32 [ %33, %29 ], [ 0, %34 ]
%37 = load i32, i32* %5
%38 = icmp sgt i32 %37, 2
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
br label %45
44: ; preds = %35
br label %45
45: ; preds = %44, %39
%46 = phi i32 [ %43, %39 ], [ 0, %44 ]
%47 = load i32, i32* %5
%48 = icmp sgt i32 %47, 3
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 3
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
br label %55
54: ; preds = %45
br label %55
55: ; preds = %54, %49
%56 = phi i32 [ %53, %49 ], [ 0, %54 ]
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i64 %22, i32 %26, i32 %36, i32 %46, i32 %56)
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %4
%60 = load i8*, i8** %6
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %59, i8* %60)
%62 = load i8*, i8** %4
store i8* %62, i8** %3
br label %69
63: ; preds = %11
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
%66 = load i32, i32* %5
%67 = add nsw i32 %66, -1
store i32 %67, i32* %5
br label %8
68: ; preds = %8
store i8* null, i8** %3
br label %69
69: ; preds = %68, %55
%70 = load i8*, i8** %3
ret i8* %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"non zero buffer at buf[%d] => 0x%02x,%02x,%02x,%02x\0A\00"
@.str.1 = [14 x i8] c"buf %p, p %p\0A\00"
define i8* @check_zero(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %41
4: ; preds = %2, %37
%5 = phi i32 [ %39, %37 ], [ %1, %2 ]
%6 = phi i8* [ %38, %37 ], [ %0, %2 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = zext i8 %7 to i32
%11 = load i32, i32* @stderr
%12 = ptrtoint i8* %6 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = icmp ugt i32 %5, 1
br i1 %15, label %16, label %28
16: ; preds = %9
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i32 %5, 2
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %6, i64 2
%22 = load i8, i8* %21
%23 = icmp ugt i32 %5, 3
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %6, i64 3
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
br label %28
28: ; preds = %9, %16, %20, %24
%29 = phi i8 [ %22, %24 ], [ %22, %20 ], [ 0, %16 ], [ 0, %9 ]
%30 = phi i8 [ %18, %24 ], [ %18, %20 ], [ %18, %16 ], [ 0, %9 ]
%31 = phi i32 [ %27, %24 ], [ 0, %20 ], [ 0, %16 ], [ 0, %9 ]
%32 = zext i8 %30 to i32
%33 = zext i8 %29 to i32
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %10, i32 %32, i32 %33, i32 %31)
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %0)
br label %41
37: ; preds = %4
%38 = getelementptr inbounds i8, i8* %6, i64 1
%39 = add nsw i32 %5, -1
%40 = icmp sgt i32 %5, 1
br i1 %40, label %4, label %41
41: ; preds = %37, %2, %28
%42 = phi i8* [ %6, %28 ], [ null, %2 ], [ null, %37 ]
ret i8* %42
}