#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 sumOfDigit(int num) {
  int sum = 0, rem = 0;
  while (num > 0) {
    while (num != 0) {
      rem = num % 10;
      sum = sum + rem;
      num = num / 10;
    }
    printf("%d\n", sum);
    if (sum > 9) {
      num = sum;
      sum = 0;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<sumOfDigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1197 <sumOfDigit+0x87>
jmp    1138 <sumOfDigit+0x28>
cmpl   $0x0,-0x4(%rbp)
je     116c <sumOfDigit+0x5c>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1138 <sumOfDigit+0x28>
mov    -0x8(%rbp),%esi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x9,-0x8(%rbp)
jle    1192 <sumOfDigit+0x82>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    1129 <sumOfDigit+0x19>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sumOfDigit>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1178 <sumOfDigit+0x68>
xor    %r14d,%r14d
lea    0xede(%rip),%rbx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
mov    %eax,%ebp
add    %esi,%ebp
add    $0x9,%ecx
mov    %ebp,%eax
cmp    $0x12,%ecx
ja     1130 <sumOfDigit+0x20>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,%eax
mov    %ebp,%edi
cmp    $0xa,%ebp
cmovge %r14d,%eax
jge    1130 <sumOfDigit+0x20>
jmp    117a <sumOfDigit+0x6a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @sumOfDigit(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %18
3: ; preds = %1, %11
%4 = phi i32 [ %12, %11 ], [ 0, %1 ]
%5 = phi i32 [ %13, %11 ], [ %0, %1 ]
%6 = srem i32 %5, 10
%7 = add nsw i32 %4, %6
%8 = sdiv i32 %5, 10
%9 = add i32 %5, 9
%10 = icmp ult i32 %9, 19
br i1 %10, label %14, label %11
11: ; preds = %3, %14
%12 = phi i32 [ %7, %3 ], [ %17, %14 ]
%13 = phi i32 [ %8, %3 ], [ %7, %14 ]
br label %3
14: ; preds = %3
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%16 = icmp sgt i32 %7, 9
%17 = select i1 %16, i32 0, i32 %7
br i1 %16, label %11, label %18
18: ; preds = %14, %1
%19 = phi i32 [ 0, %1 ], [ %17, %14 ]
ret i32 %19
}