#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 *, long *);
int main() {
  int n;
  long num;
  int sum;
  printf("enter the five-digit number: ");
  scanf("%ld", &num);
  sum = 0;
  while (num != 0) {
    n = num % 10;
    sum = sum + n;
    num = num / 10;
  }
  printf("The sum is %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1192 <main+0x72>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1154 <main+0x34>
mov    -0x14(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1192 <main+0x72>
xor    %ebx,%ebx
movabs $0x6666666666666667,%rsi
66 66 66
nopl   0x0(%rax)
mov    %rdx,%rcx
mov    %rdx,%rax
imul   %rsi
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ecx,%edi
sub    %eax,%edi
add    %edi,%ebx
add    $0x9,%rcx
cmp    $0x12,%rcx
ja     1160 <main+0x40>
mov    %rdx,0x8(%rsp)
lea    0xe89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"enter the five-digit number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [15 x i8] c"The sum is %d\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %12, %7 ], [ 0, %0 ]
%9 = phi i64 [ %13, %7 ], [ %5, %0 ]
%10 = srem i64 %9, 10
%11 = trunc i64 %10 to i32
%12 = add nsw i32 %8, %11
%13 = sdiv i64 %9, 10
%14 = add i64 %9, 9
%15 = icmp ult i64 %14, 19
br i1 %15, label %16, label %7
16: ; preds = %7
store i64 %13, i64* %1
br label %17
17: ; preds = %16, %0
%18 = phi i32 [ %12, %16 ], [ 0, %0 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}