#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 int_map {
  int dummy;
};

/* Variables and functions */
int int_map_peek(struct int_map *, int);
int /*<<< orphan*/ int_map_set(struct int_map *, int, int);
void add_feature_count(struct int_map *im, int nr, int *features, int weight) {
  int i;
  for (i = 0; i < nr; i++) {
    int f = features[i];
    int v = int_map_peek(im, f);
    int_map_set(im, f, v + weight);
  }
}


x86 assembly (clang, -O0):
<add_feature_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1186 <add_feature_count+0x66>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <int_map_peek@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
add    -0x1c(%rbp),%edx
call   1040 <int_map_set@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <add_feature_count+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_feature_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1165 <add_feature_count+0x45>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%r13
mov    %esi,%r12d
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,4),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <int_map_peek@plt>
lea    (%rax,%r14,1),%edx
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <int_map_set@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <add_feature_count+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.int_map = type { i32 }
define void @add_feature_count(%struct.int_map* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca %struct.int_map*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.int_map* %0, %struct.int_map** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %31, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32*, i32** %7
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %10
%22 = load %struct.int_map*, %struct.int_map** %5
%23 = load i32, i32* %10
%24 = call i32 @int_map_peek(%struct.int_map* %22, i32 %23)
store i32 %24, i32* %11
%25 = load %struct.int_map*, %struct.int_map** %5
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = load i32, i32* %8
%29 = add nsw i32 %27, %28
%30 = call i32 @int_map_set(%struct.int_map* %25, i32 %26, i32 %29)
br label %31
31: ; preds = %16
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %12
34: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.int_map = type { i32 }
define void @add_feature_count(%struct.int_map* %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %17
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @int_map_peek(%struct.int_map* %0, i32 %11)
%13 = add nsw i32 %12, %3
%14 = tail call i32 @int_map_set(%struct.int_map* %0, i32 %11, i32 %13)
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8, %4
ret void
}