#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 */
long htonl(int /*<<< orphan*/);
int /*<<< orphan*/ random();
int check_buffer(long *buffer, int len) {
  int i;
  for (i = 0; i < len; i++) {
    if (buffer[i] != htonl(random()))
      return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<check_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <check_buffer+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     117c <check_buffer+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1196 <check_buffer+0x76>
jmp    1181 <check_buffer+0x61>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <check_buffer+0x16>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%r14d
test   %esi,%esi
jle    1165 <check_buffer+0x45>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rbp
xor    %eax,%eax
call   1040 <random@plt>
mov    %eax,%edi
call   1030 <htonl@plt>
cmp    %rax,%rbp
jne    1162 <check_buffer+0x42>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <check_buffer+0x20>
jmp    1165 <check_buffer+0x45>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_buffer(i64* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %22, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i64*, i64** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i64, i64* %12, i64 %14
%16 = load i64, i64* %15
%17 = call i32 (...) @random()
%18 = call i64 @htonl(i32 %17)
%19 = icmp ne i64 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %11
store i32 0, i32* %3
br label %26
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %7
25: ; preds = %7
store i32 1, i32* %3
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @check_buffer(i64* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %8
%7 = icmp eq i64 %15, %5
br i1 %7, label %16, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %15, %6 ]
%10 = getelementptr inbounds i64, i64* %0, i64 %9
%11 = load i64, i64* %10
%12 = tail call i32 (...) @random()
%13 = tail call i64 @htonl(i32 %12)
%14 = icmp eq i64 %11, %13
%15 = add nuw nsw i64 %9, 1
br i1 %14, label %6, label %16
16: ; preds = %8, %6, %2
%17 = phi i32 [ 1, %2 ], [ 1, %6 ], [ 0, %8 ]
ret i32 %17
}