#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__ count(char *);
int /*<<< orphan*/ number_as_word(int, char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int i;
  int total;
  for (total = 0, i = 1; i <= 1000; ++i) {
    char buf[8192];
    number_as_word(i, buf);
    total += count(buf);
  }
  printf("%d\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jg     119a <main+0x6a>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
call   1050 <number_as_word@plt>
lea    -0x2020(%rbp),%rdi
call   1030 <count@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <main+0x27>
mov    -0x18(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    $0x1,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <number_as_word@plt>
mov    %r14,%rdi
call   1030 <count@plt>
add    %eax,%ebx
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    1150 <main+0x20>
lea    0xe8a(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 0, %2 ], [ %11, %5 ]
%7 = phi i32 [ 1, %2 ], [ %12, %5 ]
%8 = call i32 @number_as_word(i32 %7, i8* %4)
%9 = call i64 @count(i8* %4)
%10 = trunc i64 %9 to i32
%11 = add i32 %6, %10
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, 1001
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}