#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 n, a, b, c, d, sumOfDigits, reversedN, lastDigitInFirst,
      secondAndThirdExchanged;
  printf("N: ");
  scanf("%d", &n);
  a = (n / 1000) % 10;
  b = (n / 100) % 10;
  c = (n / 10) % 10;
  d = n % 10;
  sumOfDigits = a + b + c + d;
  reversedN = (d * 1000) + (c * 100) + (b * 10) + a;
  lastDigitInFirst = (d * 1000) + (a * 100) + (b * 10) + c;
  secondAndThirdExchanged = (a * 1000) + (c * 100) + (b * 10) + d;
  printf("Sum of Digits: %d\n", sumOfDigits);
  printf("Reversed N: %d\n", reversedN);
  printf("Last Digit In First Position: %d\n", lastDigitInFirst);
  printf("Exchanged Second And Third Digit: %d\n", secondAndThirdExchanged);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%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    $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)
imul   $0x3e8,-0x18(%rbp),%eax
imul   $0x64,-0x14(%rbp),%ecx
add    %ecx,%eax
imul   $0xa,-0x10(%rbp),%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
imul   $0x3e8,-0x18(%rbp),%eax
imul   $0x64,-0xc(%rbp),%ecx
add    %ecx,%eax
imul   $0xa,-0x10(%rbp),%ecx
add    %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
imul   $0x3e8,-0xc(%rbp),%eax
imul   $0x64,-0x14(%rbp),%ecx
add    %ecx,%eax
imul   $0xa,-0x10(%rbp),%ecx
add    %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
movslq 0xc(%rsp),%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%r8
imul   $0x66666667,%r8,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%r8d
imul   $0x51eb851f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x25,%rdx
add    %esi,%edx
movslq %edx,%rdx
imul   $0x66666667,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rsi
add    %edi,%esi
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%edx
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rsi
add    %edi,%esi
movslq %esi,%rsi
imul   $0x66666667,%rsi,%rdi
mov    %rdi,%rbp
shr    $0x3f,%rbp
sar    $0x22,%rdi
add    %ebp,%edi
add    %edi,%edi
lea    (%rdi,%rdi,4),%ebp
mov    %esi,%edi
sub    %ebp,%edi
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%eax
lea    (%rdx,%rax,1),%esi
add    %r8d,%esi
add    %edi,%esi
imul   $0x3e8,%eax,%ecx
imul   $0x64,%edi,%ebx
add    %edx,%edx
lea    (%rdx,%rdx,4),%ebp
add    %ebp,%ebx
lea    (%rbx,%rcx,1),%r14d
add    %r8d,%r14d
imul   $0x64,%r8d,%edx
add    %ecx,%ebp
add    %edi,%ebp
add    %edx,%ebp
imul   $0x3e8,%r8d,%ecx
add    %eax,%ebx
add    %ecx,%ebx
lea    0xde0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xde5(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"N: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Sum of Digits: %d\0A\00"
@.str.3 = [16 x i8] c"Reversed N: %d\0A\00"
@.str.4 = [34 x i8] c"Last Digit In First Position: %d\0A\00"
@.str.5 = [38 x i8] c"Exchanged Second And Third Digit: %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
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 1000
%15 = srem i32 %14, 10
store i32 %15, i32* %3
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 100
%18 = srem i32 %17, 10
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 10
%21 = srem i32 %20, 10
store i32 %21, i32* %5
%22 = load i32, i32* %2
%23 = srem i32 %22, 10
store i32 %23, i32* %6
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = add nsw i32 %24, %25
%27 = load i32, i32* %5
%28 = add nsw i32 %26, %27
%29 = load i32, i32* %6
%30 = add nsw i32 %28, %29
store i32 %30, i32* %7
%31 = load i32, i32* %6
%32 = mul nsw i32 %31, 1000
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, 100
%35 = add nsw i32 %32, %34
%36 = load i32, i32* %4
%37 = mul nsw i32 %36, 10
%38 = add nsw i32 %35, %37
%39 = load i32, i32* %3
%40 = add nsw i32 %38, %39
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = mul nsw i32 %41, 1000
%43 = load i32, i32* %3
%44 = mul nsw i32 %43, 100
%45 = add nsw i32 %42, %44
%46 = load i32, i32* %4
%47 = mul nsw i32 %46, 10
%48 = add nsw i32 %45, %47
%49 = load i32, i32* %5
%50 = add nsw i32 %48, %49
store i32 %50, i32* %9
%51 = load i32, i32* %3
%52 = mul nsw i32 %51, 1000
%53 = load i32, i32* %5
%54 = mul nsw i32 %53, 100
%55 = add nsw i32 %52, %54
%56 = load i32, i32* %4
%57 = mul nsw i32 %56, 10
%58 = add nsw i32 %55, %57
%59 = load i32, i32* %6
%60 = add nsw i32 %58, %59
store i32 %60, i32* %10
%61 = load i32, i32* %7
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %9
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %10
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"N: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Sum of Digits: %d\0A\00"
@.str.3 = [16 x i8] c"Reversed N: %d\0A\00"
@.str.4 = [34 x i8] c"Last Digit In First Position: %d\0A\00"
@.str.5 = [38 x i8] c"Exchanged Second And Third Digit: %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 ([4 x i8], [4 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 = mul nsw i32 %12, 1000
%17 = mul nsw i32 %11, 100
%18 = mul nsw i32 %9, 10
%19 = add nsw i32 %18, %17
%20 = add nsw i32 %19, %16
%21 = add nsw i32 %20, %7
%22 = mul nsw i32 %7, 100
%23 = add nsw i32 %18, %16
%24 = add nsw i32 %23, %11
%25 = add nsw i32 %24, %22
%26 = mul nsw i32 %7, 1000
%27 = add nsw i32 %19, %12
%28 = add nsw i32 %27, %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %28)
ret i32 0
}