#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, char);
int /*<<< orphan*/ stderr;
CheckZeroBuf(char *p, size_t size) {
  int i;
  for (i = 0; i < size; i++) {
    if (p[i] != '\0') {
      fprintf(stderr, "Element %d not zero ('%c')\n", i, p[i]);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<CheckZeroBuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119b <CheckZeroBuf+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1188 <CheckZeroBuf+0x68>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe8b(%rip),%rsi
movsbl (%rax,%rcx,1),%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    118d <CheckZeroBuf+0x6d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <CheckZeroBuf+0x17>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckZeroBuf>:
push   %rax
test   %rsi,%rsi
je     1141 <CheckZeroBuf+0x21>
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movzbl (%rdi,%rdx,1),%eax
test   %al,%al
jne    1143 <CheckZeroBuf+0x23>
add    $0x1,%rdx
cmp    %rdx,%rsi
jne    1130 <CheckZeroBuf+0x10>
pop    %rcx
ret
mov    0x2e96(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%ecx
lea    0xeaa(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Element %d not zero ('%c')\0A\00"
define i32 @CheckZeroBuf(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %6
br label %7
7: ; preds = %31, %2
%8 = load i32, i32* %6
%9 = sext i32 %8 to i64
%10 = load i64, i64* %5
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i32, i32* %6
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %22, i8 signext %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %7
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Element %d not zero ('%c')\0A\00"
define i32 @CheckZeroBuf(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %17, label %4
4: ; preds = %2, %14
%5 = phi i64 [ %15, %14 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = trunc i64 %5 to i32
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10, i8 signext %7)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = add nuw i64 %5, 1
%16 = icmp eq i64 %15, %1
br i1 %16, label %17, label %4
17: ; preds = %14, %2
ret i32 undef
}