#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();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void add(int *f) {
  int j = 0;
  for (int i = 0; i < 16; i++)
    j += (*(f + i) != 0) ? 1 : 0;
  if (j == 16)
    return;
  int p = 0, d = 0;
  unsigned int t;
  t = (unsigned)time(NULL);
  while (1) {
    srand(t);
    p = rand() % 16;
    if (*(f + p) == 0) {
      t++;
      srand(t);
      d = (((rand() % 2) + 1) * 2);
      break;
    } else {
      t++;
      continue;
    }
  }
  *(f + p) = d;
  return;
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1180 <add+0x50>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <add+0x1a>
cmpl   $0x10,-0xc(%rbp)
jne    118f <add+0x5f>
jmp    1221 <add+0xf1>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1205 <add+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x1,%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1213 <add+0xe3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a9 <add+0x79>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %r15
push   %r14
push   %rbx
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     11ce <add+0x9e>
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%rbx
nopl   (%rax)
mov    %ebx,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
movslq %eax,%r15
add    $0x1,%ebx
cmpl   $0x0,(%r14,%r15,4)
jne    1180 <add+0x50>
mov    %ebx,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0x7ffffffe,%ecx
sub    %ecx,%eax
add    %eax,%eax
add    $0x2,%eax
mov    %eax,(%r14,%r15,4)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @add(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %22, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 16
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32*, i32** %2
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1, i32 0
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
br label %22
22: ; preds = %11
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %8
25: ; preds = %8
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 16
br i1 %27, label %28, label %29
28: ; preds = %25
br label %61
29: ; preds = %25
store i32 0, i32* %5
store i32 0, i32* %6
%30 = call i64 @time(i32* null)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
br label %32
32: ; preds = %29, %52
%33 = load i32, i32* %7
%34 = call i32 @srand(i32 %33)
%35 = call i32 (...) @rand()
%36 = srem i32 %35, 16
store i32 %36, i32* %5
%37 = load i32*, i32** %2
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %32
%44 = load i32, i32* %7
%45 = add i32 %44, 1
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = call i32 @srand(i32 %46)
%48 = call i32 (...) @rand()
%49 = srem i32 %48, 2
%50 = add nsw i32 %49, 1
%51 = mul nsw i32 %50, 2
store i32 %51, i32* %6
br label %55
52: ; preds = %32
%53 = load i32, i32* %7
%54 = add i32 %53, 1
store i32 %54, i32* %7
br label %32
55: ; preds = %43
%56 = load i32, i32* %6
%57 = load i32*, i32** %2
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 %56, i32* %60
br label %61
61: ; preds = %55, %28
ret void
}

LLVM IR (-O2):
define void @add(i32* nocapture %0) {
%2 = bitcast 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 %27, label %7
7: ; preds = %1
%8 = tail call i64 @time(i32* null)
%9 = trunc i64 %8 to i32
br label %10
10: ; preds = %10, %7
%11 = phi i32 [ %9, %7 ], [ %19, %10 ]
%12 = tail call i32 @srand(i32 %11)
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 16
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
%19 = add i32 %11, 1
br i1 %18, label %20, label %10
20: ; preds = %10
%21 = getelementptr inbounds i32, i32* %0, i64 %15
%22 = tail call i32 @srand(i32 %19)
%23 = tail call i32 (...) @rand()
%24 = srem i32 %23, 2
%25 = shl nsw i32 %24, 1
%26 = add nsw i32 %25, 2
store i32 %26, i32* %21
br label %27
27: ; preds = %1, %20
ret void
}