#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 num;
  printf("Please enter an 4 digit integer number: ");
  scanf("%d", &num);
  int a = (num / 1000) % 10;
  int b = (num / 100) % 10;
  int c = (num / 10) % 10;
  int d = (num / 1) % 10;
  int sumOfDigits = a + b + c + d;
  printf("Sum of digits: %d\n", sumOfDigits);
  printf("Reversed: %d%d%d%d\n", d, c, b, a);
  printf("Last digit in front: %d%d%d%d\n", d, a, b, c);
  printf("Second and third digits exchanged: %d%d%d%d\n", a, c, b, d);
  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    0xee5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x1,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
movslq 0x4(%rsp),%r15
imul   $0x10624dd3,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%r14
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r14d
imul   $0x51eb851f,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%ebp
sub    %ecx,%ebp
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
lea    (%rbx,%r15,1),%esi
add    %r14d,%esi
add    %ebp,%esi
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe36(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe32(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe38(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Please enter an 4 digit integer number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Sum of digits: %d\0A\00"
@.str.3 = [20 x i8] c"Reversed: %d%d%d%d\0A\00"
@.str.4 = [31 x i8] c"Last digit in front: %d%d%d%d\0A\00"
@.str.5 = [45 x i8] c"Second and third digits exchanged: %d%d%d%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = sdiv i32 %10, 1000
%12 = srem i32 %11, 10
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 100
%15 = srem i32 %14, 10
store i32 %15, i32* %4
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 10
%18 = srem i32 %17, 10
store i32 %18, i32* %5
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 1
%21 = srem i32 %20, 10
store i32 %21, i32* %6
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
%25 = load i32, i32* %5
%26 = add nsw i32 %24, %25
%27 = load i32, i32* %6
%28 = add nsw i32 %26, %27
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* %3
%38 = load i32, i32* %4
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %37, i32 %38, i32 %39)
%41 = load i32, i32* %3
%42 = load i32, i32* %5
%43 = load i32, i32* %4
%44 = load i32, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %42, i32 %43, i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Please enter an 4 digit integer number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Sum of digits: %d\0A\00"
@.str.3 = [20 x i8] c"Reversed: %d%d%d%d\0A\00"
@.str.4 = [31 x i8] c"Last digit in front: %d%d%d%d\0A\00"
@.str.5 = [45 x i8] c"Second and third digits exchanged: %d%d%d%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 ([41 x i8], [41 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 = sdiv i32 %5, 1000
%7 = srem i32 %6, 10
%8 = sdiv i32 %5, 100
%9 = srem i32 %8, 10
%10 = sdiv i32 %5, 10
%11 = srem i32 %10, 10
%12 = srem i32 %5, 10
%13 = add nsw i32 %9, %12
%14 = add nsw i32 %13, %7
%15 = add nsw i32 %14, %11
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %11, i32 %9, i32 %7)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %7, i32 %9, i32 %11)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 %11, i32 %9, i32 %12)
ret i32 0
}