#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*/ fill(int **, int);
int rand();
void add(int a[][4]) {
  int i, j, zero = 0;
  for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++)
      if (!a[i][j])
        zero++;
  if (!zero)
    return;
  int x = rand() % zero;
  fill(a, x);
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    11a1 <add+0x81>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    118e <add+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    117b <add+0x5b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <add+0x60>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <add+0x2b>
jmp    1193 <add+0x73>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <add+0x1a>
cmpl   $0x0,-0x14(%rbp)
jne    11b0 <add+0x90>
jmp    11ca <add+0xaa>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <fill@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %rbx
push   %rax
movdqu (%rdi),%xmm0
movdqu 0x10(%rdi),%xmm1
movdqu 0x20(%rdi),%xmm2
movdqu 0x30(%rdi),%xmm3
pxor   %xmm4,%xmm4
pcmpeqd %xmm4,%xmm3
pcmpeqd %xmm4,%xmm2
packssdw %xmm3,%xmm2
pcmpeqd %xmm4,%xmm1
pcmpeqd %xmm4,%xmm0
packssdw %xmm1,%xmm0
packsswb %xmm2,%xmm0
pmovmskb %xmm0,%eax
test   %eax,%eax
je     11b0 <add+0x90>
mov    %rdi,%rbx
mov    %eax,%ecx
shr    %ecx
and    $0x5555,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
and    $0x3333,%ecx
shr    $0x2,%eax
and    $0x3333,%eax
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x4,%ecx
add    %eax,%ecx
and    $0xf0f,%ecx
mov    %ecx,%eax
shl    $0x8,%eax
add    %ecx,%eax
movzbl %ah,%ebp
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %ebp
mov    %rbx,%rdi
mov    %edx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fill@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @add([4 x i32]* %0) {
%2 = bitcast [4 x i32]* %0 to <16 x i32>*
%3 = load <16 x i32>, <16 x i32>* %2
%4 = icmp eq <16 x i32> %3, zeroinitializer
%5 = bitcast <16 x i1> %4 to i16
%6 = icmp eq i16 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i16 @llvm.ctpop.i16(i16 %5)
%9 = zext i16 %8 to i32
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, %9
%12 = bitcast [4 x i32]* %0 to i32**
%13 = tail call i32 @fill(i32** %12, i32 %11)
br label %14
14: ; preds = %1, %7
ret void
}