#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 */
char getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int strlen(char *);
int main() {
  char messaggio[160 + 1];
  int i;
  int chiave;
  int len;
  printf("Scrivere un SMS su una riga (massimo %d caratteri):\n"
         "---premere invio per terminare il messaggio---\n",
         160);
  gets(messaggio);
  do {
    printf("Inserire la chiave di cifratura: intero in [%d, %d]: ", 0, 10);
    scanf("%d", &chiave);
    if (chiave < 0 || chiave > 10)
      printf("Chiave non valida!");
  } while (chiave < 0 || chiave > 10);
  len = strlen(messaggio);
  printf("Messaggio cifrato:\n");
  for (i = 0; i < len + 1; i++)
    printf("%c", messaggio[len - i] + chiave);
  printf("\n\n");
  while (getchar() != '\n')
    ;
  printf("Scrivere l'SMS cifrato su una riga (massimo %d caratteri):\n"
         "---premere invio per terminare il messaggio---\n",
         160);
  gets(messaggio);
  len = strlen(messaggio);
  for (i = len; i > 0; i--)
    printf("%c", messaggio[i - 1] - chiave);
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
mov    $0xa0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   1060 <gets@plt>
lea    0xedc(%rip),%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xefd(%rip),%rdi
lea    -0xb8(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,-0xb8(%rbp)
jl     11c3 <main+0x73>
cmpl   $0xa,-0xb8(%rbp)
jle    11d1 <main+0x81>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d6 <main+0x86>
mov    $0x1,%al
cmpl   $0x0,-0xb8(%rbp)
mov    %al,-0xbd(%rbp)
jl     11fb <main+0xab>
cmpl   $0xa,-0xb8(%rbp)
setg   %al
mov    %al,-0xbd(%rbp)
mov    -0xbd(%rbp),%al
test   $0x1,%al
jne    1181 <main+0x31>
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xbc(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
mov    -0xbc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1288 <main+0x138>
mov    -0xbc(%rbp),%eax
sub    -0xb4(%rbp),%eax
cltq
movsbl -0xb0(%rbp,%rax,1),%esi
ff
add    -0xb8(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1233 <main+0xe3>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12ae <main+0x15e>
jmp    1296 <main+0x146>
lea    0xe15(%rip),%rdi
mov    $0xa0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   1060 <gets@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jle    1333 <main+0x1e3>
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0xb0(%rbp,%rax,1),%esi
ff
sub    -0xb8(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xb4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xb4(%rbp)
jmp    12eb <main+0x19b>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe7b(%rip),%rdi
mov    $0xa0,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
call   1080 <gets@plt>
lea    0xec2(%rip),%r14
lea    0xef1(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xee8(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
cmpl   $0xb,0xc(%rsp)
jb     11f4 <main+0x84>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0xa,0xc(%rsp)
ja     11c0 <main+0x50>
lea    0x10(%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xf13(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
js     1247 <main+0xd7>
mov    %r14d,%eax
add    $0x1,%r14d
lea    (%rsp,%rax,1),%r15
add    $0x10,%r15
neg    %r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
add    0xc(%rsp),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    %rbx,%r14
jne    1230 <main+0xc0>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1260 <main+0xf0>
lea    0xe3e(%rip),%rdi
mov    $0xa0,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    12bb <main+0x14b>
mov    %eax,%ebx
add    $0x1,%rbx
nopl   (%rax)
lea    -0x2(%rbx),%eax
movsbl 0x10(%rsp,%rax,1),%edi
sub    0xc(%rsp),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     12a0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [100 x i8] c"Scrivere un SMS su una riga (massimo %d caratteri):\0A---premere invio per terminare il messaggio---\0A\00"
@.str.1 = [54 x i8] c"Inserire la chiave di cifratura: intero in [%d, %d]: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Chiave non valida!\00"
@.str.4 = [20 x i8] c"Messaggio cifrato:\0A\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
@.str.7 = [107 x i8] c"Scrivere l'SMS cifrato su una riga (massimo %d caratteri):\0A---premere invio per terminare il messaggio---\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [161 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i32 160)
%7 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
br label %9
9: ; preds = %26, %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 10)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 10
br i1 %16, label %17, label %19
17: ; preds = %14, %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 10
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ true, %20 ], [ %25, %23 ]
br i1 %27, label %9, label %28
28: ; preds = %26
%29 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %32
32: ; preds = %48, %28
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %51
37: ; preds = %32
%38 = load i32, i32* %5
%39 = load i32, i32* %3
%40 = sub nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = load i32, i32* %4
%46 = add nsw i32 %44, %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %37
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %32
51: ; preds = %32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %57, %51
%54 = call signext i8 (...) @getchar()
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 10
br i1 %56, label %57, label %58
57: ; preds = %53
br label %53
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.7, i64 0, i64 0), i32 160)
%60 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 0
%61 = call i32 @gets(i8* %60)
%62 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
store i32 %63, i32* %5
%64 = load i32, i32* %5
store i32 %64, i32* %3
br label %65
65: ; preds = %78, %58
%66 = load i32, i32* %3
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %81
68: ; preds = %65
%69 = load i32, i32* %3
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [161 x i8], [161 x i8]* %2, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = load i32, i32* %4
%76 = sub nsw i32 %74, %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %68
%79 = load i32, i32* %3
%80 = add nsw i32 %79, -1
store i32 %80, i32* %3
br label %65
81: ; preds = %65
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
@.str = [100 x i8] c"Scrivere un SMS su una riga (massimo %d caratteri):\0A---premere invio per terminare il messaggio---\0A\00"
@.str.1 = [54 x i8] c"Inserire la chiave di cifratura: intero in [%d, %d]: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Chiave non valida!\00"
@.str.7 = [107 x i8] c"Scrivere l'SMS cifrato su una riga (massimo %d caratteri):\0A---premere invio per terminare il messaggio---\0A\00"
@str = [19 x i8] c"Messaggio cifrato:\00"
@str.9 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [161 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [161 x i8], [161 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i32 160)
%6 = call i32 @gets(i8* %3)
br label %7
7: ; preds = %12, %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 10)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp ugt i32 %10, 10
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* %2
%15 = icmp ugt i32 %14, 10
br i1 %15, label %7, label %16
16: ; preds = %7, %12
%17 = call i32 @strlen(i8* %3)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%19 = icmp slt i32 %17, 0
br i1 %19, label %35, label %20
20: ; preds = %16
%21 = zext i32 %17 to i64
%22 = add nuw i32 %17, 1
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %20, %24
%25 = phi i64 [ 0, %20 ], [ %33, %24 ]
%26 = sub nsw i64 %21, %25
%27 = getelementptr inbounds [161 x i8], [161 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = load i32, i32* %2
%31 = add nsw i32 %30, %29
%32 = call i32 @putchar(i32 %31)
%33 = add nuw nsw i64 %25, 1
%34 = icmp eq i64 %33, %23
br i1 %34, label %35, label %24
35: ; preds = %24, %16
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
br label %37
37: ; preds = %37, %35
%38 = call signext i8 (...) @getchar()
%39 = icmp eq i8 %38, 10
br i1 %39, label %40, label %37
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([107 x i8], [107 x i8]* @.str.7, i64 0, i64 0), i32 160)
%42 = call i32 @gets(i8* %3)
%43 = call i32 @strlen(i8* %3)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %58
45: ; preds = %40
%46 = zext i32 %43 to i64
br label %47
47: ; preds = %45, %47
%48 = phi i64 [ %46, %45 ], [ %49, %47 ]
%49 = add nsw i64 %48, -1
%50 = and i64 %49, 4294967295
%51 = getelementptr inbounds [161 x i8], [161 x i8]* %1, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = load i32, i32* %2
%55 = sub nsw i32 %53, %54
%56 = call i32 @putchar(i32 %55)
%57 = icmp ugt i64 %48, 1
br i1 %57, label %47, label %58
58: ; preds = %47, %40
%59 = call i32 @putchar(i32 10)
ret i32 0
}