#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 */
typedef int /*<<< orphan*/ string;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned short *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ xor_char_by_char(char *, unsigned short);
int main(void) {
  unsigned short key;
  char string[100];
  printf("write a text to encrypt: ");
  fgets(string, sizeof(string), stdin);
  printf("write key (integer 1,...,256): ");
  scanf("%hu", &key);
  key = (key % 256);
  xor_char_by_char(string, key);
  printf(" encrypted text: %s", string);
  xor_char_by_char(string, key);
  printf("dencrypted text: %s", string);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x6(%rbp),%rsi
call   1060 <scanf@plt>
movzwl -0x6(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
mov    %ax,-0x6(%rbp)
lea    -0x70(%rbp),%rdi
movzwl -0x6(%rbp),%esi
call   1030 <xor_char_by_char@plt>
lea    -0x70(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
movzwl -0x6(%rbp),%esi
call   1030 <xor_char_by_char@plt>
lea    -0x70(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1060 <scanf@plt>
movzbl 0xe(%rsp),%eax
mov    %ax,0xe(%rsp)
movzwl %ax,%esi
mov    %rbx,%rdi
call   1030 <xor_char_by_char@plt>
lea    0xe92(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0xe(%rsp),%esi
mov    %rbx,%rdi
call   1030 <xor_char_by_char@plt>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"write a text to encrypt: \00"
@stdin = global i32 0
@.str.1 = [32 x i8] c"write key (integer 1,...,256): \00"
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [20 x i8] c" encrypted text: %s\00"
@.str.4 = [20 x i8] c"dencrypted text: %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca [100 x i8]
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 100, i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%10 = load i16, i16* %2
%11 = zext i16 %10 to i32
%12 = srem i32 %11, 256
%13 = trunc i32 %12 to i16
store i16 %13, i16* %2
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = load i16, i16* %2
%16 = call i32 @xor_char_by_char(i8* %14, i16 zeroext %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = load i16, i16* %2
%21 = call i32 @xor_char_by_char(i8* %19, i16 zeroext %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}

LLVM IR (-O2):
@.str = [26 x i8] c"write a text to encrypt: \00"
@stdin = global i32 0
@.str.1 = [32 x i8] c"write key (integer 1,...,256): \00"
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [20 x i8] c" encrypted text: %s\00"
@.str.4 = [20 x i8] c"dencrypted text: %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i16
%2 = alloca [100 x i8]
%3 = bitcast i16* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 100, i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %1)
%10 = load i16, i16* %1
%11 = and i16 %10, 255
store i16 %11, i16* %1
%12 = call i32 @xor_char_by_char(i8* %4, i16 zeroext %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%14 = load i16, i16* %1
%15 = call i32 @xor_char_by_char(i8* %4, i16 zeroext %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}