#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() {
  int n = 100000000;
  printf("\nFinding sum of multiples of 3 and 5 below %d\n", n);
  long total = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 3 == 0) {
      total = total + i;
    } else if (i % 5 == 0) {
      total = total + i;
    }
  }
  printf("Result: %ld\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5f5e100,-0x8(%rbp)
movslq -0x8(%rbp),%rsi
lea    0xecf(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b4 <main+0xa4>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1179 <main+0x69>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11a1 <main+0x91>
mov    -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119c <main+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11a1 <main+0x91>
jmp    11a6 <main+0x96>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <main+0x35>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x5f5e100,%esi
call   1030 <printf@plt>
xor    %eax,%eax
mov    $0xcccccccd,%r8d
mov    $0xaaaaaaab,%r9d
xor    %esi,%esi
jmp    114f <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %rcx,%rsi
add    $0x1,%rax
cmp    $0x5f5e100,%rax
je     1180 <main+0x70>
mov    %eax,%edi
mov    %rdi,%rcx
imul   %r9,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%edx
mov    %rax,%rcx
cmp    %edx,%eax
je     1140 <main+0x30>
imul   %r8,%rdi
shr    $0x22,%rdi
lea    (%rdi,%rdi,4),%ecx
neg    %ecx
add    %eax,%ecx
mov    $0x0,%ecx
cmove  %rax,%rcx
jmp    1140 <main+0x30>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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