#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 bsd_rand_actual();
int /*<<< orphan*/ printf(char *, int, int, unsigned int);
int rand();
int bsd_rand_wrapper(void) {
  static unsigned cidx = 0;
  int ret = bsd_rand_actual();
  int cmp = rand();
  if (ret != cmp) {
    printf("ERROR: rand() inconsistency %i (system) vs %i (custom) at call "
           "number %u\n",
           cmp, ret, cidx);
  }
  ++cidx;
  return ret;
}


x86 assembly (clang, -O0):
<bsd_rand_wrapper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <bsd_rand_actual@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1170 <bsd_rand_wrapper+0x40>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    0x2ed8(%rip),%ecx
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ec6(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ebd(%rip)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bsd_rand_wrapper>:
push   %rbx
xor    %eax,%eax
call   1040 <bsd_rand_actual@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <rand@plt>
cmp    %eax,%ebx
je     115b <bsd_rand_wrapper+0x2b>
mov    0x2ef1(%rip),%ecx
lea    0xeae(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
addl   $0x1,0x2eda(%rip)
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@bsd_rand_wrapper.cidx = internal global i32 0
@.str = [74 x i8] c"ERROR: rand() inconsistency %i (system) vs %i (custom) at call number %u\0A\00"
define i32 @bsd_rand_wrapper() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @bsd_rand_actual()
store i32 %3, i32* %1
%4 = call i32 (...) @rand()
store i32 %4, i32* %2
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* %2
%10 = load i32, i32* %1
%11 = load i32, i32* @bsd_rand_wrapper.cidx
%12 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
br label %13
13: ; preds = %8, %0
%14 = load i32, i32* @bsd_rand_wrapper.cidx
%15 = add i32 %14, 1
store i32 %15, i32* @bsd_rand_wrapper.cidx
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@bsd_rand_wrapper.cidx = internal unnamed_addr global i32 0
@.str = [74 x i8] c"ERROR: rand() inconsistency %i (system) vs %i (custom) at call number %u\0A\00"
define i32 @bsd_rand_wrapper() {
%1 = tail call i32 (...) @bsd_rand_actual()
%2 = tail call i32 (...) @rand()
%3 = icmp eq i32 %1, %2
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i32, i32* @bsd_rand_wrapper.cidx
%6 = tail call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %1, i32 %5)
br label %7
7: ; preds = %4, %0
%8 = load i32, i32* @bsd_rand_wrapper.cidx
%9 = add i32 %8, 1
store i32 %9, i32* @bsd_rand_wrapper.cidx
ret i32 %1
}