#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 EXIT_FAILURE;
int EXIT_SUCCESS;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int lseek(int, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, unsigned int);
char *mmap(int /*<<< orphan*/ *, unsigned int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, unsigned int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
unsigned int posix1c_rand_r(unsigned int *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int make_randbitmap(unsigned int seed, double density, unsigned int bitsnumber,
                    char *filename) {
  int fd;
  char *addr;
  int result;
  unsigned int randval, randint, randmod;
  unsigned int filesize;
  unsigned int bitstofill;
  if (density < 0.0f || density > 1.0f) {
    fprintf(stderr, "density >= 0 && density <= 1\n");
    return EXIT_FAILURE;
  }
  filesize = bitsnumber / 8 + !!(bitsnumber % 8);
  bitstofill = bitsnumber * density;
  fd = open(filename, O_RDWR | O_CREAT | O_TRUNC,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (fd == -1) {
    perror("open");
    return EXIT_FAILURE;
  }
  result = lseek(fd, filesize - 1, SEEK_SET);
  if (result == -1) {
    close(fd);
    perror("lseek");
    return EXIT_FAILURE;
  }
  result = write(fd, "", 1);
  if (result != 1) {
    close(fd);
    perror("writing last byte");
    return (EXIT_FAILURE);
  }
  addr = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (addr == MAP_FAILED) {
    close(fd);
    perror("mmap");
    return EXIT_FAILURE;
  }
  if (density > 0.5f) {
    memset(addr, '\255', filesize);
    bitstofill = bitsnumber - bitstofill;
  }
  while (bitstofill) {
    randval = posix1c_rand_r(&seed) % bitsnumber;
    randint = randval / 8;
    randmod = randval % 8;
    if (density > 0.5f) {
      if (!(~addr[randint] & 1 << randmod)) {
        addr[randint] = ~(~addr[randint] | 1 << randmod);
        --bitstofill;
      }
    } else {
      if (!(addr[randint] & 1 << randmod)) {
        addr[randint] = addr[randint] | 1 << randmod;
        --bitstofill;
      }
    }
  }
  munmap(addr, filesize);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<make_randbitmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     11dc <make_randbitmap+0x3c>
movsd  -0x10(%rbp),%xmm0
movsd  0xe2e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1202 <make_randbitmap+0x62>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14ed <make_randbitmap+0x34d>
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
shr    $0x3,%eax
and    $0x7,%ecx
sub    $0x1,%ecx
sbb    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    0x2db5(%rip),%rax
or     (%rax),%esi
mov    0x2da4(%rip),%rax
or     (%rax),%esi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
mov    0x2d62(%rip),%rax
or     (%rax),%edx
mov    0x2d39(%rip),%rax
or     (%rax),%edx
mov    0x2d28(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12a1 <make_randbitmap+0x101>
lea    0xda3(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14ed <make_randbitmap+0x34d>
mov    -0x24(%rbp),%edi
mov    -0x44(%rbp),%esi
sub    $0x1,%esi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    12ea <make_randbitmap+0x14a>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xd5f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14ed <make_randbitmap+0x34d>
mov    -0x24(%rbp),%edi
lea    0xd39(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
je     1330 <make_randbitmap+0x190>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xd1f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14ed <make_randbitmap+0x34d>
mov    -0x44(%rbp),%esi
mov    0x2cae(%rip),%rax
mov    (%rax),%edx
mov    0x2c45(%rip),%rax
or     (%rax),%edx
mov    0x2c8c(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2c03(%rip),%rcx
cmp    (%rcx),%rax
jne    139b <make_randbitmap+0x1fb>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xcc6(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14ed <make_randbitmap+0x34d>
movsd  -0x10(%rbp),%xmm0
movsd  0xc60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    13cc <make_randbitmap+0x22c>
mov    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    $0xffffffad,%esi
call   1070 <memset@plt>
mov    -0x14(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    13d1 <make_randbitmap+0x231>
cmpl   $0x0,-0x48(%rbp)
je     14cd <make_randbitmap+0x32d>
lea    -0x8(%rbp),%rdi
call   1050 <posix1c_rand_r@plt>
xor    %edx,%edx
divl   -0x14(%rbp)
mov    %edx,-0x38(%rbp)
mov    -0x38(%rbp),%eax
shr    $0x3,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xbfd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1473 <make_randbitmap+0x2d3>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
xor    $0xffffffff,%eax
mov    -0x40(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    146e <make_randbitmap+0x2ce>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
xor    $0xffffffff,%eax
mov    -0x40(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
xor    $0xffffffff,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    14c8 <make_randbitmap+0x328>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x40(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    14c3 <make_randbitmap+0x323>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x40(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    14c8 <make_randbitmap+0x328>
jmp    13d1 <make_randbitmap+0x231>
mov    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   10a0 <munmap@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x2a90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_randbitmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,0xc(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1382 <make_randbitmap+0x1e2>
ucomisd 0xe38(%rip),%xmm0
ja     1382 <make_randbitmap+0x1e2>
mov    %esi,%r13d
movsd  %xmm0,0x10(%rsp)
mov    %esi,%r14d
shr    $0x3,%r14d
mov    %esi,%eax
and    $0x7,%eax
cmp    $0x1,%eax
sbb    $0xffffffff,%r14d
mov    0x2dd7(%rip),%rax
mov    0x2e00(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ded(%rip),%rax
or     (%rax),%esi
mov    0x2d74(%rip),%rcx
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2d82(%rip),%rcx
or     (%rcx),%eax
mov    0x2d71(%rip),%rcx
or     (%rcx),%eax
mov    %rdx,%rdi
mov    %eax,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     13cc <make_randbitmap+0x22c>
mov    %eax,%ebx
lea    -0x1(%r14),%esi
mov    0x2d5f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     13d5 <make_randbitmap+0x235>
lea    0xdcb(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    13e5 <make_randbitmap+0x245>
mov    0x2d6a(%rip),%rax
mov    0x2d03(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d48(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbp
mov    0x2cc4(%rip),%rax
cmp    (%rax),%rbp
je     13f5 <make_randbitmap+0x255>
mov    %ebx,0x8(%rsp)
mov    %r13d,%eax
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r15
ucomisd 0xd30(%rip),%xmm1
jbe    12f3 <make_randbitmap+0x153>
mov    %rbp,%rdi
mov    $0xffffffad,%esi
mov    %r14d,%edx
call   1070 <memset@plt>
mov    %r13d,%eax
sub    %r15d,%eax
mov    %eax,%r15d
test   %r15d,%r15d
je     13a0 <make_randbitmap+0x200>
lea    0xc(%rsp),%r12
jmp    1322 <make_randbitmap+0x182>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %sil,0x0(%rbp,%rax,1)
add    $0xffffffff,%r15d
test   %r15d,%r15d
je     13a0 <make_randbitmap+0x200>
mov    %r12,%rdi
call   1050 <posix1c_rand_r@plt>
xor    %edx,%edx
div    %r13d
mov    %edx,%ecx
mov    %rcx,%rax
shr    $0x3,%rax
and    $0x7,%ecx
movsd  0x10(%rsp),%xmm0
ucomisd 0xcbf(%rip),%xmm0
movzbl 0x0(%rbp,%rax,1),%edx
jbe    1370 <make_randbitmap+0x1d0>
mov    %edx,%ebx
not    %bl
movzbl %bl,%edi
mov    $0x1,%esi
shl    %cl,%esi
bt     %ecx,%edi
jb     1319 <make_randbitmap+0x179>
not    %sil
and    %dl,%sil
jmp    1310 <make_randbitmap+0x170>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%esi
shl    %cl,%esi
bt     %ecx,%edx
jb     1319 <make_randbitmap+0x179>
or     %esi,%edx
mov    %edx,%esi
jmp    1310 <make_randbitmap+0x170>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
lea    0xc7e(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2bf2(%rip),%rax
jmp    13bb <make_randbitmap+0x21b>
mov    %rbp,%rdi
mov    %r14d,%esi
call   10a0 <munmap@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x2bbd(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc5b(%rip),%rdi
jmp    1403 <make_randbitmap+0x263>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xc50(%rip),%rdi
jmp    1403 <make_randbitmap+0x263>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xc46(%rip),%rdi
jmp    1403 <make_randbitmap+0x263>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xc48(%rip),%rdi
call   10c0 <perror@plt>
jmp    1397 <make_randbitmap+0x1f7>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"density >= 0 && density <= 1\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [18 x i8] c"writing last byte\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [5 x i8] c"mmap\00"
@EXIT_SUCCESS = global i32 0
define i32 @make_randbitmap(i32 %0, double %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %6
store double %1, double* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%18 = load double, double* %7
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load double, double* %7
%22 = fcmp ogt double %21, 1.000000e+00
br i1 %22, label %23, label %27
23: ; preds = %20, %4
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %5
br label %193
27: ; preds = %20
%28 = load i32, i32* %8
%29 = udiv i32 %28, 8
%30 = load i32, i32* %8
%31 = urem i32 %30, 8
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
%36 = add i32 %29, %35
store i32 %36, i32* %16
%37 = load i32, i32* %8
%38 = uitofp i32 %37 to double
%39 = load double, double* %7
%40 = fmul double %38, %39
%41 = fptoui double %40 to i32
store i32 %41, i32* %17
%42 = load i8*, i8** %9
%43 = load i32, i32* @O_RDWR
%44 = load i32, i32* @O_CREAT
%45 = or i32 %43, %44
%46 = load i32, i32* @O_TRUNC
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IRUSR
%49 = load i32, i32* @S_IWUSR
%50 = or i32 %48, %49
%51 = load i32, i32* @S_IRGRP
%52 = or i32 %50, %51
%53 = load i32, i32* @S_IROTH
%54 = or i32 %52, %53
%55 = call i32 @open(i8* %42, i32 %47, i32 %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %27
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
store i32 %60, i32* %5
br label %193
61: ; preds = %27
%62 = load i32, i32* %10
%63 = load i32, i32* %16
%64 = sub i32 %63, 1
%65 = load i32, i32* @SEEK_SET
%66 = call i32 @lseek(i32 %62, i32 %64, i32 %65)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %74
69: ; preds = %61
%70 = load i32, i32* %10
%71 = call i32 @close(i32 %70)
%72 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %5
br label %193
74: ; preds = %61
%75 = load i32, i32* %10
%76 = call i32 @write(i32 %75, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %76, i32* %12
%77 = load i32, i32* %12
%78 = icmp ne i32 %77, 1
br i1 %78, label %79, label %84
79: ; preds = %74
%80 = load i32, i32* %10
%81 = call i32 @close(i32 %80)
%82 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
store i32 %83, i32* %5
br label %193
84: ; preds = %74
%85 = load i32, i32* %16
%86 = load i32, i32* @PROT_READ
%87 = load i32, i32* @PROT_WRITE
%88 = or i32 %86, %87
%89 = load i32, i32* @MAP_SHARED
%90 = load i32, i32* %10
%91 = call i8* @mmap(i32* null, i32 %85, i32 %88, i32 %89, i32 %90, i32 0)
store i8* %91, i8** %11
%92 = load i8*, i8** %11
%93 = load i8*, i8** @MAP_FAILED
%94 = icmp eq i8* %92, %93
br i1 %94, label %95, label %100
95: ; preds = %84
%96 = load i32, i32* %10
%97 = call i32 @close(i32 %96)
%98 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
store i32 %99, i32* %5
br label %193
100: ; preds = %84
%101 = load double, double* %7
%102 = fcmp ogt double %101, 5.000000e-01
br i1 %102, label %103, label %110
103: ; preds = %100
%104 = load i8*, i8** %11
%105 = load i32, i32* %16
%106 = call i32 @memset(i8* %104, i8 signext -83, i32 %105)
%107 = load i32, i32* %8
%108 = load i32, i32* %17
%109 = sub i32 %107, %108
store i32 %109, i32* %17
br label %110
110: ; preds = %103, %100
br label %111
111: ; preds = %185, %110
%112 = load i32, i32* %17
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %186
114: ; preds = %111
%115 = call i32 @posix1c_rand_r(i32* %6)
%116 = load i32, i32* %8
%117 = urem i32 %115, %116
store i32 %117, i32* %13
%118 = load i32, i32* %13
%119 = udiv i32 %118, 8
store i32 %119, i32* %14
%120 = load i32, i32* %13
%121 = urem i32 %120, 8
store i32 %121, i32* %15
%122 = load double, double* %7
%123 = fcmp ogt double %122, 5.000000e-01
br i1 %123, label %124, label %156
124: ; preds = %114
%125 = load i8*, i8** %11
%126 = load i32, i32* %14
%127 = zext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %125, i64 %127
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = xor i32 %130, -1
%132 = load i32, i32* %15
%133 = shl i32 1, %132
%134 = and i32 %131, %133
%135 = icmp ne i32 %134, 0
br i1 %135, label %155, label %136
136: ; preds = %124
%137 = load i8*, i8** %11
%138 = load i32, i32* %14
%139 = zext i32 %138 to i64
%140 = getelementptr inbounds i8, i8* %137, i64 %139
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = xor i32 %142, -1
%144 = load i32, i32* %15
%145 = shl i32 1, %144
%146 = or i32 %143, %145
%147 = xor i32 %146, -1
%148 = trunc i32 %147 to i8
%149 = load i8*, i8** %11
%150 = load i32, i32* %14
%151 = zext i32 %150 to i64
%152 = getelementptr inbounds i8, i8* %149, i64 %151
store i8 %148, i8* %152
%153 = load i32, i32* %17
%154 = add i32 %153, -1
store i32 %154, i32* %17
br label %155
155: ; preds = %136, %124
br label %185
156: ; preds = %114
%157 = load i8*, i8** %11
%158 = load i32, i32* %14
%159 = zext i32 %158 to i64
%160 = getelementptr inbounds i8, i8* %157, i64 %159
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = load i32, i32* %15
%164 = shl i32 1, %163
%165 = and i32 %162, %164
%166 = icmp ne i32 %165, 0
br i1 %166, label %184, label %167
167: ; preds = %156
%168 = load i8*, i8** %11
%169 = load i32, i32* %14
%170 = zext i32 %169 to i64
%171 = getelementptr inbounds i8, i8* %168, i64 %170
%172 = load i8, i8* %171
%173 = sext i8 %172 to i32
%174 = load i32, i32* %15
%175 = shl i32 1, %174
%176 = or i32 %173, %175
%177 = trunc i32 %176 to i8
%178 = load i8*, i8** %11
%179 = load i32, i32* %14
%180 = zext i32 %179 to i64
%181 = getelementptr inbounds i8, i8* %178, i64 %180
store i8 %177, i8* %181
%182 = load i32, i32* %17
%183 = add i32 %182, -1
store i32 %183, i32* %17
br label %184
184: ; preds = %167, %156
br label %185
185: ; preds = %184, %155
br label %111
186: ; preds = %111
%187 = load i8*, i8** %11
%188 = load i32, i32* %16
%189 = call i32 @munmap(i8* %187, i32 %188)
%190 = load i32, i32* %10
%191 = call i32 @close(i32 %190)
%192 = load i32, i32* @EXIT_SUCCESS
store i32 %192, i32* %5
br label %193
193: ; preds = %186, %95, %79, %69, %58, %23
%194 = load i32, i32* %5
ret i32 %194
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"density >= 0 && density <= 1\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [18 x i8] c"writing last byte\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [5 x i8] c"mmap\00"
@EXIT_SUCCESS = global i32 0
define i32 @make_randbitmap(i32 %0, double %1, i32 %2, i8* nocapture %3) {
%5 = alloca i32
store i32 %0, i32* %5
%6 = fcmp olt double %1, 0.000000e+00
%7 = fcmp ogt double %1, 1.000000e+00
%8 = or i1 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %106
12: ; preds = %4
%13 = lshr i32 %2, 3
%14 = and i32 %2, 7
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %13, %16
%18 = uitofp i32 %2 to double
%19 = fmul double %18, %1
%20 = fptoui double %19 to i32
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IROTH
%32 = or i32 %30, %31
%33 = tail call i32 @open(i8* %3, i32 %25, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %12
%36 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %106
37: ; preds = %12
%38 = add nsw i32 %17, -1
%39 = load i32, i32* @SEEK_SET
%40 = tail call i32 @lseek(i32 %33, i32 %38, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = tail call i32 @close(i32 %33)
%44 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %106
45: ; preds = %37
%46 = tail call i32 @write(i32 %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%47 = icmp eq i32 %46, 1
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = tail call i32 @close(i32 %33)
%50 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %106
51: ; preds = %45
%52 = load i32, i32* @PROT_READ
%53 = load i32, i32* @PROT_WRITE
%54 = or i32 %53, %52
%55 = load i32, i32* @MAP_SHARED
%56 = tail call i8* @mmap(i32* null, i32 %17, i32 %54, i32 %55, i32 %33, i32 0)
%57 = load i8*, i8** @MAP_FAILED
%58 = icmp eq i8* %56, %57
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = tail call i32 @close(i32 %33)
%61 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %106
62: ; preds = %51
%63 = fcmp ogt double %1, 5.000000e-01
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = tail call i32 @memset(i8* %56, i8 signext -83, i32 %17)
%66 = sub i32 %2, %20
br label %67
67: ; preds = %64, %62
%68 = phi i32 [ %66, %64 ], [ %20, %62 ]
%69 = icmp eq i32 %68, 0
br i1 %69, label %103, label %70
70: ; preds = %67, %100
%71 = phi i32 [ %101, %100 ], [ %68, %67 ]
%72 = call i32 @posix1c_rand_r(i32* %5)
%73 = urem i32 %72, %2
%74 = lshr i32 %73, 3
%75 = and i32 %73, 7
%76 = zext i32 %74 to i64
%77 = getelementptr inbounds i8, i8* %56, i64 %76
%78 = load i8, i8* %77
br i1 %63, label %79, label %89
79: ; preds = %70
%80 = xor i8 %78, -1
%81 = zext i8 %80 to i32
%82 = shl nuw nsw i32 1, %75
%83 = and i32 %82, %81
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %100
85: ; preds = %79
%86 = trunc i32 %82 to i8
%87 = xor i8 %86, -1
%88 = and i8 %78, %87
br label %97
89: ; preds = %70
%90 = zext i8 %78 to i32
%91 = shl nuw nsw i32 1, %75
%92 = and i32 %91, %90
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %89
%95 = trunc i32 %91 to i8
%96 = or i8 %78, %95
br label %97
97: ; preds = %85, %94
%98 = phi i8 [ %96, %94 ], [ %88, %85 ]
store i8 %98, i8* %77
%99 = add i32 %71, -1
br label %100
100: ; preds = %97, %89, %79
%101 = phi i32 [ %71, %79 ], [ %71, %89 ], [ %99, %97 ]
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %70
103: ; preds = %100, %67
%104 = call i32 @munmap(i8* %56, i32 %17)
%105 = call i32 @close(i32 %33)
br label %106
106: ; preds = %103, %59, %48, %42, %35, %9
%107 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_FAILURE, %35 ], [ @EXIT_FAILURE, %42 ], [ @EXIT_FAILURE, %48 ], [ @EXIT_FAILURE, %59 ], [ @EXIT_SUCCESS, %103 ]
%108 = load i32, i32* %107
ret i32 %108
}