#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 rand();
void blewgap(unsigned char **p) {
  int gaplen = (rand() % (16 - 8)) + 8;
  unsigned char *buf = *p;
  (*p) += gaplen;
  while (gaplen--)
    *buf++ = rand() & 0xff;
}


x86 assembly (clang, -O0):
<blewgap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x8,%edx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1187 <blewgap+0x77>
mov    $0x0,%al
call   1030 <rand@plt>
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    114f <blewgap+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blewgap>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <rand@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
mov    %eax,%edx
sub    %ecx,%edx
neg    %ecx
add    %ecx,%eax
add    $0x8,%eax
mov    (%r14),%r15
add    %r15,%rax
mov    %rax,(%r14)
movslq %edx,%r14
add    $0x8,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r14d
jne    1150 <blewgap+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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