#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 d(int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int a, b, sum = 0;
  for (a = 1; a < 10000; ++a) {
    b = d(a);
    if (d(b) == a && a != b)
      sum += a;
  }
  printf("%d\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    118e <main+0x6e>
mov    -0x8(%rbp),%edi
call   1030 <d@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <d@plt>
cmp    -0x8(%rbp),%eax
jne    117b <main+0x5b>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     117b <main+0x5b>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <main+0x60>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113d <main+0x1d>
mov    -0x10(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1154 <main+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r14d,%ebp
cmove  %r15d,%ecx
add    %ecx,%ebx
add    $0x1,%ebp
cmp    $0x2710,%ebp
je     1172 <main+0x52>
mov    %ebp,%edi
call   1030 <d@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1030 <d@plt>
mov    $0x0,%ecx
cmp    %eax,%ebp
jne    1140 <main+0x20>
mov    %ebp,%ecx
jmp    1140 <main+0x20>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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