#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 *, int);
int main() {
  int i, n, sum, first_digit, digit;
  i = 1000;
  while (i <= 9999) {
    first_digit = i / 1000;
    n = i % 1000;
    sum = 0;
    while (n > 0) {
      digit = n % 10;
      sum += digit;
      n /= 10;
    }
    if (sum == first_digit)
      printf("%d\t", i);
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
cmpl   $0x270f,-0x8(%rbp)
jg     11b3 <main+0xa3>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    118a <main+0x7a>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x46>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11a5 <main+0x95>
mov    -0x8(%rbp),%esi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x3e8,%ebp
lea    0xee0(%rip),%r14
mov    $0xcccccccd,%ebx
jmp    113b <main+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x2710,%ebp
je     11a3 <main+0x93>
movzwl %bp,%ecx
mov    %ecx,%eax
shr    $0x3,%eax
imul   $0x20c5,%eax,%r8d
shr    $0x14,%r8d
imul   $0x3e8,%r8d,%edx
sub    %dx,%cx
je     1190 <main+0x80>
movzwl %cx,%eax
xor    %ecx,%ecx
nop
mov    %eax,%esi
imul   %rbx,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %eax,%edx
sub    %edi,%edx
add    %edx,%ecx
cmp    $0x9,%eax
mov    %esi,%eax
ja     1160 <main+0x50>
cmp    %r8d,%ecx
jne    1130 <main+0x20>
jmp    1197 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
cmp    %r8d,%ecx
jne    1130 <main+0x20>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
jmp    1130 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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