#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() {
  long num;
  int sum, n;
  int i;
  printf("enter the 4 digit number: ");
  scanf("%ld", &num);
  i = 1;
  sum = 0;
  while (num != 0) {
    n = num % 10;
    if (i == 1 || i == 4)
      sum = sum + n;
    num = num / 10;
    i++;
  }
  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    0xed7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     118d <main+0x6d>
cmpl   $0x4,-0x1c(%rbp)
jne    1196 <main+0x76>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <main+0x3b>
mov    -0x14(%rbp),%esi
lea    0xe5f(%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    0xedf(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11b5 <main+0x95>
xor    %ebx,%ebx
mov    $0x1,%esi
movabs $0x6666666666666667,%r8
66 66 66
jmp    1190 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rdi,%rcx
sub    %rax,%rcx
add    %ecx,%ebx
add    $0x1,%esi
add    $0x9,%rdi
cmp    $0x12,%rdi
mov    %rdx,%rdi
jbe    11b0 <main+0x90>
mov    %rdi,%rax
imul   %r8
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
cmp    $0x4,%esi
je     1170 <main+0x50>
cmp    $0x1,%esi
je     1170 <main+0x50>
jmp    1180 <main+0x60>
mov    %rdx,0x8(%rsp)
lea    0xe63(%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 = [27 x i8] c"enter the 4 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 i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
store i32 1, i32* %5
store i32 0, i32* %3
br label %8
8: ; preds = %24, %0
%9 = load i64, i64* %2
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i64, i64* %2
%13 = srem i64 %12, 10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %24
20: ; preds = %17, %11
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = add nsw i32 %21, %22
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %17
%25 = load i64, i64* %2
%26 = sdiv i64 %25, 10
store i64 %26, i64* %2
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %8
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"enter the 4 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 ([27 x i8], [27 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 %22, label %7
7: ; preds = %0, %16
%8 = phi i32 [ %18, %16 ], [ 1, %0 ]
%9 = phi i32 [ %17, %16 ], [ 0, %0 ]
%10 = phi i64 [ %11, %16 ], [ %5, %0 ]
%11 = sdiv i64 %10, 10
%12 = srem i64 %10, 10
switch i32 %8, label %16 [
i32 4, label %13
i32 1, label %13
]
13: ; preds = %7, %7
%14 = trunc i64 %12 to i32
%15 = add nsw i32 %9, %14
br label %16
16: ; preds = %7, %13
%17 = phi i32 [ %15, %13 ], [ %9, %7 ]
%18 = add nuw nsw i32 %8, 1
%19 = add i64 %10, 9
%20 = icmp ult i64 %19, 19
br i1 %20, label %21, label %7
21: ; preds = %16
store i64 %11, i64* %1
br label %22
22: ; preds = %21, %0
%23 = phi i32 [ %17, %21 ], [ 0, %0 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 0
}