#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 main() {
  int counter = 0;
  int is3 = 3;
  int i = 0;
  for (i = 0; i < 1000; i += 5) {
    if (is3 == 3) {
      is3 = 1;
      continue;
    }
    counter += i;
    is3++;
  }
  for (i = 0; i < 1000; i += 3) {
    counter += i;
  }
  printf("sum: %d\n", counter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    117e <main+0x6e>
cmpl   $0x3,-0xc(%rbp)
jne    115e <main+0x4e>
movl   $0x1,-0xc(%rbp)
jmp    1170 <main+0x60>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <main+0x2b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    11a9 <main+0x99>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <main+0x75>
mov    -0x8(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x3,%edi
xor    %r8d,%r8d
mov    $0x1,%r9d
xor    %r10d,%r10d
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rdi),%eax
cmp    $0x3,%edi
mov    %r10d,%edi
cmove  %r8d,%edi
cmove  %r9d,%eax
add    %esi,%edi
lea    0x1(%rax),%esi
lea    0x5(%r10),%ecx
cmp    $0x3,%eax
cmove  %r8d,%ecx
cmove  %r9d,%esi
add    %edi,%ecx
lea    0x1(%rsi),%eax
lea    0xa(%r10),%edx
cmp    $0x3,%esi
cmove  %r8d,%edx
cmove  %r9d,%eax
add    %ecx,%edx
lea    0x1(%rax),%edi
lea    0xf(%r10),%esi
cmp    $0x3,%eax
cmove  %r8d,%esi
cmove  %r9d,%edi
add    %edx,%esi
lea    0x14(%r10),%eax
cmp    $0x3d4,%r10d
mov    %eax,%r10d
jb     1130 <main+0x20>
push   %rax
add    $0x28bb1,%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"sum: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %28, %1 ]
%3 = phi i32 [ 3, %0 ], [ %27, %1 ]
%4 = phi i32 [ 0, %0 ], [ %26, %1 ]
%5 = icmp eq i32 %3, 3
%6 = add nsw i32 %3, 1
%7 = select i1 %5, i32 0, i32 %2
%8 = add nuw nsw i32 %7, %4
%9 = select i1 %5, i32 1, i32 %6
%10 = add nuw nsw i32 %2, 5
%11 = icmp eq i32 %9, 3
%12 = add nsw i32 %9, 1
%13 = select i1 %11, i32 0, i32 %10
%14 = add nuw nsw i32 %13, %8
%15 = select i1 %11, i32 1, i32 %12
%16 = add nuw nsw i32 %2, 10
%17 = icmp eq i32 %15, 3
%18 = add nsw i32 %15, 1
%19 = select i1 %17, i32 0, i32 %16
%20 = add nuw nsw i32 %19, %14
%21 = select i1 %17, i32 1, i32 %18
%22 = add nuw nsw i32 %2, 15
%23 = icmp eq i32 %21, 3
%24 = add nsw i32 %21, 1
%25 = select i1 %23, i32 0, i32 %22
%26 = add nuw nsw i32 %25, %20
%27 = select i1 %23, i32 1, i32 %24
%28 = add nuw nsw i32 %2, 20
%29 = icmp ult i32 %2, 980
br i1 %29, label %1, label %30
30: ; preds = %1
%31 = add nuw i32 %26, 166833
%32 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %31)
ret i32 0
}