#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);
void main(void) {
  int count = 0;
  int ratio = 5;
  int limit = 40;
  while (count < limit) {
    int rem = count % ratio;
    if (rem) {
      printf("Ratio hit! [%d]\n", count);
    } else {
      printf("No hit! [%d]\n", count);
    }
    count++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x28,-0xc(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117e <main+0x6e>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1161 <main+0x51>
mov    -0x4(%rbp),%esi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
jmp    1170 <main+0x60>
mov    -0x4(%rbp),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112d <main+0x1d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
lea    0xef3(%rip),%r14
lea    0xedb(%rip),%r15
jmp    113f <main+0x2f>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x28,%ebx
je     115c <main+0x4c>
movzbl %bl,%eax
imul   $0xcd,%eax,%ecx
shr    $0xa,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
mov    %r14,%rdi
add    %cl,%al
je     1130 <main+0x20>
mov    %r15,%rdi
jmp    1130 <main+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Ratio hit! [%d]\0A\00"
@.str.1 = [14 x i8] c"No hit! [%d]\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %2
store i32 40, i32* %3
br label %5
5: ; preds = %21, %0
%6 = load i32, i32* %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %24
9: ; preds = %5
%10 = load i32, i32* %1
%11 = load i32, i32* %2
%12 = srem i32 %10, %11
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %21
18: ; preds = %9
%19 = load i32, i32* %1
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %5
24: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Ratio hit! [%d]\0A\00"
@.str.1 = [14 x i8] c"No hit! [%d]\0A\00"
define void @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %8, %1 ]
%3 = trunc i32 %2 to i8
%4 = urem i8 %3, 5
%5 = icmp eq i8 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0)
%7 = tail call i32 @printf(i8* %6, i32 %2)
%8 = add nuw nsw i32 %2, 1
%9 = icmp eq i32 %8, 40
br i1 %9, label %10, label %1
10: ; preds = %1
ret void
}