#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*/ printf(char *, char *, int);
int rand();
void *realloc(void *, size_t);
void *oom_realloc(char *file, int line, void *ptr, size_t size) {
  if ((rand() % 20) == 0) {
    printf("oom_remalloc(): returning NULL at %s:%d\n", file, line);
    return NULL;
  }
  return realloc(ptr, size);
}


x86 assembly (clang, -O0):
<oom_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117f <oom_realloc+0x4f>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1190 <oom_realloc+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oom_realloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <rand@plt>
imul   $0xcccccccd,%eax,%eax
add    $0x19999998,%eax
ror    $0x2,%eax
cmp    $0xccccccc,%eax
jbe    1174 <oom_realloc+0x44>
mov    %rbp,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <realloc@plt>
lea    0xe85(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"oom_remalloc(): returning NULL at %s:%d\0A\00"
define i8* @oom_realloc(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 20
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
store i8* null, i8** %5
br label %21
17: ; preds = %4
%18 = load i8*, i8** %8
%19 = load i64, i64* %9
%20 = call i8* @realloc(i8* %18, i64 %19)
store i8* %20, i8** %5
br label %21
21: ; preds = %17, %13
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@.str = [41 x i8] c"oom_remalloc(): returning NULL at %s:%d\0A\00"
define noalias i8* @oom_realloc(i8* %0, i32 %1, i8* nocapture %2, i64 %3) {
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 20
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
br label %12
10: ; preds = %4
%11 = tail call i8* @realloc(i8* %2, i64 %3)
br label %12
12: ; preds = %10, %8
%13 = phi i8* [ null, %8 ], [ %11, %10 ]
ret i8* %13
}