#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 */
struct belief {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ combine_message(struct belief *, struct belief *,
                                   unsigned int, unsigned int);
void read_incoming_messages(struct belief *message_buffer,
                            unsigned int *dest_node_to_edges_nodes,
                            unsigned int *dest_node_to_edges_edges,
                            struct belief *previous_messages,
                            unsigned int num_edges, unsigned int num_vertices,
                            unsigned int num_variables, int i) {
  unsigned int start_index, end_index, j, edge_index;
  start_index = dest_node_to_edges_nodes[i];
  if (i + 1 >= num_vertices) {
    end_index = num_edges;
  } else {
    end_index = dest_node_to_edges_nodes[i + 1];
  }
  for (j = start_index; j < end_index; ++j) {
    edge_index = dest_node_to_edges_edges[j];
    combine_message(message_buffer, previous_messages, num_variables,
                    edge_index);
  }
}


x86 assembly (clang, -O0):
<read_incoming_messages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq 0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x28(%rbp),%eax
jb     115e <read_incoming_messages+0x4e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1171 <read_incoming_messages+0x61>
mov    -0x10(%rbp),%rax
mov    0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    11b1 <read_incoming_messages+0xa1>
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x10(%rbp),%edx
mov    -0x38(%rbp),%ecx
call   1030 <combine_message@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1177 <read_incoming_messages+0x67>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_incoming_messages>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r13
movslq 0x48(%rsp),%rax
mov    (%rsi,%rax,4),%ebp
add    $0x1,%eax
cmp    %r9d,%eax
jae    113a <read_incoming_messages+0x2a>
cltq
mov    (%rsi,%rax,4),%r8d
cmp    %r8d,%ebp
jae    116a <read_incoming_messages+0x5a>
mov    0x40(%rsp),%r12d
mov    %r8d,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbp,4),%ecx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <combine_message@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1150 <read_incoming_messages+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.belief = type { i32 }
define void @read_incoming_messages(%struct.belief* %0, i32* nocapture %1, i32* nocapture %2, %struct.belief* %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %7, 1
%13 = icmp ult i32 %12, %5
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
br label %18
18: ; preds = %8, %14
%19 = phi i32 [ %17, %14 ], [ %4, %8 ]
%20 = icmp ult i32 %11, %19
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = zext i32 %11 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ %22, %21 ], [ %28, %23 ]
%25 = getelementptr inbounds i32, i32* %2, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 @combine_message(%struct.belief* %0, %struct.belief* %3, i32 %6, i32 %26)
%28 = add nuw nsw i64 %24, 1
%29 = trunc i64 %28 to i32
%30 = icmp eq i32 %19, %29
br i1 %30, label %31, label %23
31: ; preds = %23, %18
ret void
}