#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, temp, d, s = 0;
  printf("Enter number\n");
  scanf("%d", &n);
  temp = n;
  while (n > 0) {
    d = n % 10;
    s = s + d;
    n /= 10;
  }
  printf("SUM = %d", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    118e <main+0x6e>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    115a <main+0x3a>
mov    -0x14(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xec2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
xor    %esi,%esi
test   %eax,%eax
jle    1181 <main+0x51>
mov    $0xcccccccd,%r8d
xchg   %ax,%ax
mov    %eax,%ecx
mov    %eax,%eax
imul   %r8,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ecx,%edx
sub    %edi,%edx
add    %edx,%esi
cmp    $0x9,%ecx
ja     1160 <main+0x30>
mov    %eax,0x4(%rsp)
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Enter number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"SUM = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
store i32 %8, i32* %3
br label %9
9: ; preds = %12, %0
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %2
%14 = srem i32 %13, 10
store i32 %14, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
store i32 %17, i32* %5
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 10
store i32 %19, i32* %2
br label %9
20: ; preds = %9
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"SUM = %d\00"
@str = [13 x i8] c"Enter number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ 0, %0 ]
%9 = phi i32 [ %12, %7 ], [ %5, %0 ]
%10 = urem i32 %9, 10
%11 = add nuw nsw i32 %8, %10
%12 = udiv i32 %9, 10
%13 = icmp ult i32 %9, 10
br i1 %13, label %14, label %7
14: ; preds = %7
store i32 %12, i32* %1
br label %15
15: ; preds = %14, %0
%16 = phi i32 [ %11, %14 ], [ 0, %0 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret i32 0
}