#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(void) {
  int number;
  int sum;
  printf("Enter number: ");
  scanf("%i", &number);
  if (number != 1) {
    while (number > 1) {
      sum += number % 10;
      number /= 10;
    }
  } else {
    sum = 1;
  }
  printf("Sum is %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
je     118f <main+0x6f>
jmp    115c <main+0x3c>
cmpl   $0x1,-0x8(%rbp)
jle    118a <main+0x6a>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    115c <main+0x3c>
jmp    1196 <main+0x76>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    $0x1,%esi
cmp    $0x1,%eax
je     1181 <main+0x61>
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
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    $0x13,%ecx
ja     1160 <main+0x40>
mov    %eax,0x4(%rsp)
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"Enter number: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [11 x i8] c"Sum is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 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 eq i32 %5, 1
br i1 %6, label %17, label %7
7: ; preds = %0
%8 = icmp sgt i32 %5, 1
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ %13, %9 ], [ undef, %7 ]
%11 = phi i32 [ %14, %9 ], [ %5, %7 ]
%12 = urem i32 %11, 10
%13 = add nsw i32 %10, %12
%14 = udiv i32 %11, 10
%15 = icmp ugt i32 %11, 19
br i1 %15, label %9, label %16
16: ; preds = %9
store i32 %14, i32* %1
br label %17
17: ; preds = %16, %0
%18 = phi i32 [ 1, %0 ], [ %13, %16 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}