#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 geturand();
int /*<<< orphan*/ printf(char *, int, int);
void dist(int mask, int iters) {
  int h[256] = {0};
  int i, j;
  for (i = 0; i < iters; i++) {
    j = geturand();
    if (j < 0)
      continue;
    h[j % mask]++;
  }
  for (i = 0; i < mask; i++)
    printf("%d %d\n", i, h[i]);
}


x86 assembly (clang, -O0):
<dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11be <dist+0x8e>
mov    $0x0,%al
call   1040 <geturand@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
jge    118c <dist+0x5c>
jmp    11aa <dist+0x7a>
mov    -0x418(%rbp),%eax
cltd
idivl  -0x4(%rbp)
movslq %edx,%rax
mov    -0x410(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x410(%rbp,%rax,4)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    115e <dist+0x2e>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120b <dist+0xdb>
mov    -0x414(%rbp),%esi
movslq -0x414(%rbp),%rax
mov    -0x410(%rbp,%rax,4),%edx
lea    0xe0e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11c8 <dist+0x98>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
test   %ebp,%ebp
jg     11a5 <dist+0x75>
test   %ebx,%ebx
jle    1186 <dist+0x56>
mov    %ebx,%ebp
xor    %ebx,%ebx
lea    0xe9f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <dist+0x40>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     1152 <dist+0x22>
xor    %eax,%eax
call   1040 <geturand@plt>
test   %eax,%eax
js     11a0 <dist+0x70>
cltd
idiv   %ebx
addl   $0x1,(%rsp,%rdx,4)
jmp    11a0 <dist+0x70>

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
define void @dist(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i32]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [256 x i32]* %5 to i8*
store i32 0, i32* %6
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = call i32 (...) @geturand()
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %26
18: ; preds = %13
%19 = load i32, i32* %7
%20 = load i32, i32* %3
%21 = srem i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %23
br label %26
26: ; preds = %18, %17
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %9
29: ; preds = %9
store i32 0, i32* %6
br label %30
30: ; preds = %41, %29
%31 = load i32, i32* %6
%32 = load i32, i32* %3
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %39)
br label %41
41: ; preds = %34
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %30
44: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
define void @dist(i32 %0, i32 %1) {
%3 = alloca [256 x i32]
%4 = bitcast [256 x i32]* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %10, label %6
6: ; preds = %20, %2
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %31
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %23
10: ; preds = %2, %20
%11 = phi i32 [ %21, %20 ], [ 0, %2 ]
%12 = tail call i32 (...) @geturand()
%13 = icmp slt i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = srem i32 %12, %0
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
br label %20
20: ; preds = %10, %14
%21 = add nuw nsw i32 %11, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %6, label %10
23: ; preds = %8, %23
%24 = phi i64 [ 0, %8 ], [ %29, %23 ]
%25 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = trunc i64 %24 to i32
%28 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %26)
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, %9
br i1 %30, label %31, label %23
31: ; preds = %23, %6
ret void
}