#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 /*<<< orphan*/ printf(char *, int, int);
void frequency(int *counter) {
  int i = 0;
  for (i = 1; i <= 42; i++) {
    if (*(counter + i) != 0) {
      printf("%i has been picked %i times\n", i, *(counter + i));
    }
  }
}


x86 assembly (clang, -O0):
<frequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x2a,-0xc(%rbp)
jg     1173 <frequency+0x63>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1160 <frequency+0x50>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
jmp    1165 <frequency+0x55>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <frequency+0x1a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frequency>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%ebx
lea    0xedc(%rip),%r15
jmp    113a <frequency+0x2a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x2b,%rbx
je     114e <frequency+0x3e>
mov    (%r14,%rbx,4),%edx
test   %edx,%edx
je     1130 <frequency+0x20>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    1130 <frequency+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"%i has been picked %i times\0A\00"
define void @frequency(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 1, i32* %3
br label %4
4: ; preds = %23, %1
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 42
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = load i32*, i32** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
%12 = load i32, i32* %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = load i32, i32* %3
%16 = load i32*, i32** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %20)
br label %22
22: ; preds = %14, %7
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %4
26: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"%i has been picked %i times\0A\00"
define void @frequency(i32* nocapture %0) {
br label %2
2: ; preds = %1, %10
%3 = phi i64 [ 1, %1 ], [ %11, %10 ]
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = trunc i64 %3 to i32
%9 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %5)
br label %10
10: ; preds = %2, %7
%11 = add nuw nsw i64 %3, 1
%12 = icmp eq i64 %11, 43
br i1 %12, label %13, label %2
13: ; preds = %10
ret void
}