#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 *, long);
int main() {
  long int sum = 0, i, flag;
  for (i = 1; i < 1000; i++) {
    flag = 1;
    if ((i % 3) == 0) {
      flag = 0;
      sum = sum + i;
    } else if (((i % 5) == 0) && flag == 1) {
      sum = sum + i;
    }
  }
  printf("%ld", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
cmpq   $0x3e8,-0x18(%rbp)
jge    11c0 <main+0xb0>
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1176 <main+0x66>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11aa <main+0x9a>
mov    -0x18(%rbp),%rax
mov    $0x5,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11a5 <main+0x95>
cmpq   $0x1,-0x20(%rbp)
jne    11a5 <main+0x95>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11aa <main+0x9a>
jmp    11af <main+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112f <main+0x1f>
mov    -0x10(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
xor    %esi,%esi
jmp    112f <main+0x1f>
nopl   0x0(%rax)
add    %rdx,%rsi
add    $0x1,%rax
cmp    $0x3e8,%rax
je     1167 <main+0x57>
movzwl %ax,%ecx
imul   $0xaaab,%ecx,%edx
shr    $0x11,%edx
lea    (%rdx,%rdx,2),%edi
neg    %edi
mov    %rax,%rdx
add    %ax,%di
je     1120 <main+0x10>
imul   $0xcccd,%ecx,%ecx
shr    $0x12,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
movzwl %cx,%ecx
add    %ax,%cx
mov    $0x0,%edx
cmove  %rax,%rdx
jmp    1120 <main+0x10>
push   %rax
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @main() {
br label %1
1: ; preds = %0, %11
%2 = phi i64 [ 1, %0 ], [ %14, %11 ]
%3 = phi i64 [ 0, %0 ], [ %13, %11 ]
%4 = trunc i64 %2 to i16
%5 = urem i16 %4, 3
%6 = icmp eq i16 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = urem i16 %4, 5
%9 = icmp eq i16 %8, 0
%10 = select i1 %9, i64 %2, i64 0
br label %11
11: ; preds = %1, %7
%12 = phi i64 [ %10, %7 ], [ %2, %1 ]
%13 = add nsw i64 %12, %3
%14 = add nuw nsw i64 %2, 1
%15 = icmp eq i64 %14, 1000
br i1 %15, label %16, label %1
16: ; preds = %11
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
ret i32 0
}