int sum_of_multiples(int n) {
  int sum = 0;
  n = n - 1;
  sum = ((n / 3) * ((n / 3) * 3 + 3)) / 2 + ((n / 5) * ((n / 5) * 5 + 5)) / 2 -
        ((n / 15) * ((n / 15) * 15 + 15)) / 2;
  return sum;
}


x86 assembly (clang, -O0):
<sum_of_multiples>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   $0x3,%ecx,%ecx
add    $0x3,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   $0x5,%ecx,%ecx
add    $0x5,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   $0xf,%ecx,%ecx
add    $0xf,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_of_multiples>:
lea    -0x1(%rdi),%eax
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
add    %edx,%eax
lea    (%rax,%rax,2),%edx
add    $0x3,%edx
imul   %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
sar    %eax
add    %edx,%eax
lea    (%rax,%rax,4),%edx
add    $0x5,%edx
imul   %eax,%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
add    %esi,%eax
imul   $0xffffffff88888889,%rcx,%rcx
shr    $0x20,%rcx
add    %edi,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,2),%edx
add    $0xf,%edx
imul   %ecx,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
sar    %ecx
sub    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @sum_of_multiples(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = sub nsw i32 %4, 1
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 3
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 3
%10 = mul nsw i32 %9, 3
%11 = add nsw i32 %10, 3
%12 = mul nsw i32 %7, %11
%13 = sdiv i32 %12, 2
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 5
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 5
%18 = mul nsw i32 %17, 5
%19 = add nsw i32 %18, 5
%20 = mul nsw i32 %15, %19
%21 = sdiv i32 %20, 2
%22 = add nsw i32 %13, %21
%23 = load i32, i32* %2
%24 = sdiv i32 %23, 15
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 15
%27 = mul nsw i32 %26, 15
%28 = add nsw i32 %27, 15
%29 = mul nsw i32 %24, %28
%30 = sdiv i32 %29, 2
%31 = sub nsw i32 %22, %30
store i32 %31, i32* %3
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @sum_of_multiples(i32 %0) {
%2 = add nsw i32 %0, -1
%3 = sdiv i32 %2, 3
%4 = mul nsw i32 %3, 3
%5 = add nsw i32 %4, 3
%6 = mul nsw i32 %5, %3
%7 = sdiv i32 %6, 2
%8 = sdiv i32 %2, 5
%9 = mul nsw i32 %8, 5
%10 = add nsw i32 %9, 5
%11 = mul nsw i32 %10, %8
%12 = sdiv i32 %11, 2
%13 = add nsw i32 %7, %12
%14 = sdiv i32 %2, 15
%15 = mul nsw i32 %14, 15
%16 = add nsw i32 %15, 15
%17 = mul nsw i32 %16, %14
%18 = sdiv i32 %17, -2
%19 = add i32 %13, %18
ret i32 %19
}