#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__ calloc(int, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *);
int *read_votes(int p, int d) {
  int *votes = (int *)calloc(d << 1, sizeof(int));
  while (p--) {
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    votes[(x - 1) << 1] += a;
    votes[((x - 1) << 1) + 1] += b;
  }
  return votes;
}


x86 assembly (clang, -O0):
<read_votes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
shl    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11a8 <read_votes+0x88>
lea    0xea3(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <scanf@plt>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
jmp    1142 <read_votes+0x22>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_votes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    (%rsi,%rsi,1),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     119e <read_votes+0x7e>
lea    0xeb5(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x14(%rsp),%r13
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
mov    0xc(%rsp),%ecx
add    %ecx,%ecx
add    $0xfffffffe,%ecx
movslq %ecx,%rcx
add    %eax,(%r14,%rcx,4)
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%ecx
add    %ecx,%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
add    %eax,(%r14,%rcx,4)
add    $0xffffffff,%ebx
jne    1160 <read_votes+0x40>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
define i32* @read_votes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = shl i32 %1, 1
%7 = tail call i64 @calloc(i32 %6, i32 4)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i32 %0, 0
br i1 %9, label %35, label %10
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
br label %14
14: ; preds = %10, %14
%15 = phi i32 [ %0, %10 ], [ %16, %14 ]
%16 = add nsw i32 %15, -1
%17 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = shl i32 %19, 1
%21 = add i32 %20, -2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %8, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %18
store i32 %25, i32* %23
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = shl i32 %27, 1
%29 = add i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %8, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %26
store i32 %33, i32* %31
%34 = icmp eq i32 %16, 0
br i1 %34, label %35, label %14
35: ; preds = %14, %2
ret i32* %8
}