#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 */
scalar_t__ digitcount(int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  digitcount(1000);
  digitcount(999);
  digitcount(342);
  digitcount(325);
  digitcount(300);
  digitcount(115);
  digitcount(99);
  digitcount(50);
  digitcount(19);
  digitcount(17);
  digitcount(10);
  digitcount(8);
  digitcount(4);
  digitcount(1);
  int sum = 0;
  for (int i = 1; i <= 1000; ++i) {
    sum += digitcount(i);
  }
  printf("sum 1,1000: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1040 <digitcount@plt>
mov    $0x3e7,%edi
call   1040 <digitcount@plt>
mov    $0x156,%edi
call   1040 <digitcount@plt>
mov    $0x145,%edi
call   1040 <digitcount@plt>
mov    $0x12c,%edi
call   1040 <digitcount@plt>
mov    $0x73,%edi
call   1040 <digitcount@plt>
mov    $0x63,%edi
call   1040 <digitcount@plt>
mov    $0x32,%edi
call   1040 <digitcount@plt>
mov    $0x13,%edi
call   1040 <digitcount@plt>
mov    $0x11,%edi
call   1040 <digitcount@plt>
mov    $0xa,%edi
call   1040 <digitcount@plt>
mov    $0x8,%edi
call   1040 <digitcount@plt>
mov    $0x4,%edi
call   1040 <digitcount@plt>
mov    $0x1,%edi
call   1040 <digitcount@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jg     11f9 <main+0xd9>
mov    -0xc(%rbp),%edi
call   1040 <digitcount@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c9 <main+0xa9>
mov    -0x8(%rbp),%esi
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3e8,%edi
call   1040 <digitcount@plt>
mov    $0x3e7,%edi
call   1040 <digitcount@plt>
mov    $0x156,%edi
call   1040 <digitcount@plt>
mov    $0x145,%edi
call   1040 <digitcount@plt>
mov    $0x12c,%edi
call   1040 <digitcount@plt>
mov    $0x73,%edi
call   1040 <digitcount@plt>
mov    $0x63,%edi
call   1040 <digitcount@plt>
mov    $0x32,%edi
call   1040 <digitcount@plt>
mov    $0x13,%edi
call   1040 <digitcount@plt>
mov    $0x11,%edi
call   1040 <digitcount@plt>
mov    $0xa,%edi
call   1040 <digitcount@plt>
mov    $0x8,%edi
call   1040 <digitcount@plt>
mov    $0x4,%edi
call   1040 <digitcount@plt>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1040 <digitcount@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <digitcount@plt>
add    %eax,%ebx
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    11c0 <main+0xa0>
lea    0xe25(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"sum 1,1000: %d\0A\00"
define i32 @main() {
%1 = tail call i64 @digitcount(i32 1000)
%2 = tail call i64 @digitcount(i32 999)
%3 = tail call i64 @digitcount(i32 342)
%4 = tail call i64 @digitcount(i32 325)
%5 = tail call i64 @digitcount(i32 300)
%6 = tail call i64 @digitcount(i32 115)
%7 = tail call i64 @digitcount(i32 99)
%8 = tail call i64 @digitcount(i32 50)
%9 = tail call i64 @digitcount(i32 19)
%10 = tail call i64 @digitcount(i32 17)
%11 = tail call i64 @digitcount(i32 10)
%12 = tail call i64 @digitcount(i32 8)
%13 = tail call i64 @digitcount(i32 4)
%14 = tail call i64 @digitcount(i32 1)
br label %17
15: ; preds = %17
%16 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
17: ; preds = %0, %17
%18 = phi i32 [ 1, %0 ], [ %23, %17 ]
%19 = phi i32 [ 0, %0 ], [ %22, %17 ]
%20 = tail call i64 @digitcount(i32 %18)
%21 = trunc i64 %20 to i32
%22 = add i32 %19, %21
%23 = add nuw nsw i32 %18, 1
%24 = icmp eq i32 %23, 1001
br i1 %24, label %15, label %17
}