#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 */
scalar_t__ RAND_MAX;
scalar_t__ rand();
int conn_marking_uniform(int *conn_buffer, short *external_cell,
                         int global_cell_id, int local_nw_size, int nw_size,
                         double probability, int core_id) {
  int total_amount_connections = 0, sender_cell;
  float rndm;
  for (sender_cell = 0; sender_cell < nw_size; sender_cell++) {
    if (sender_cell == global_cell_id)
      ;
    else {
      rndm = ((float)rand()) / ((float)RAND_MAX);
      if (rndm <= probability) {
        total_amount_connections++;
        conn_buffer[sender_cell]++;
        if ((sender_cell / local_nw_size) != core_id)
          external_cell[sender_cell] = 1;
      }
    }
  }
  return total_amount_connections;
}


x86 assembly (clang, -O0):
<conn_marking_uniform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ec <conn_marking_uniform+0xdc>
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    115e <conn_marking_uniform+0x4e>
jmp    11d9 <conn_marking_uniform+0xc9>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e77(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11d4 <conn_marking_uniform+0xc4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    -0x2c(%rbp),%eax
je     11cf <conn_marking_uniform+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movw   $0x1,(%rax,%rcx,2)
jmp    11d4 <conn_marking_uniform+0xc4>
jmp    11d9 <conn_marking_uniform+0xc9>
jmp    11de <conn_marking_uniform+0xce>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1141 <conn_marking_uniform+0x31>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_marking_uniform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x4(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %ecx,(%rsp)
mov    %rsi,0x8(%rsp)
test   %r8d,%r8d
jle    11ac <conn_marking_uniform+0x9c>
mov    %rdi,%r13
mov    %edx,%r14d
mov    %r8d,%r15d
mov    0x2ea2(%rip),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1159 <conn_marking_uniform+0x49>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11ae <conn_marking_uniform+0x9e>
cmp    %rbx,%r14
je     1150 <conn_marking_uniform+0x40>
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r12),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     1150 <conn_marking_uniform+0x40>
addl   $0x1,0x0(%r13,%rbx,4)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idivl  (%rsp)
cmp    0x4(%rsp),%eax
je     1150 <conn_marking_uniform+0x40>
mov    0x8(%rsp),%rax
movw   $0x1,(%rax,%rbx,2)
jmp    1150 <conn_marking_uniform+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i32 @conn_marking_uniform(i32* nocapture %0, i16* nocapture writeonly %1, i32 %2, i32 %3, i32 %4, double %5, i32 %6) {
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %38
9: ; preds = %7
%10 = zext i32 %2 to i64
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %9, %34
%13 = phi i64 [ 0, %9 ], [ %36, %34 ]
%14 = phi i32 [ 0, %9 ], [ %35, %34 ]
%15 = icmp eq i64 %13, %10
br i1 %15, label %34, label %16
16: ; preds = %12
%17 = tail call i64 (...) @rand()
%18 = sitofp i64 %17 to float
%19 = load i64, i64* @RAND_MAX
%20 = sitofp i64 %19 to float
%21 = fdiv float %18, %20
%22 = fpext float %21 to double
%23 = fcmp ugt double %22, %5
br i1 %23, label %34, label %24
24: ; preds = %16
%25 = add nsw i32 %14, 1
%26 = getelementptr inbounds i32, i32* %0, i64 %13
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = trunc i64 %13 to i32
%30 = sdiv i32 %29, %3
%31 = icmp eq i32 %30, %6
br i1 %31, label %34, label %32
32: ; preds = %24
%33 = getelementptr inbounds i16, i16* %1, i64 %13
store i16 1, i16* %33
br label %34
34: ; preds = %12, %24, %32, %16
%35 = phi i32 [ %14, %12 ], [ %25, %32 ], [ %25, %24 ], [ %14, %16 ]
%36 = add nuw nsw i64 %13, 1
%37 = icmp eq i64 %36, %11
br i1 %37, label %38, label %12
38: ; preds = %34, %7
%39 = phi i32 [ 0, %7 ], [ %35, %34 ]
ret i32 %39
}