#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ ioctl(int, int, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_buf(char *, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main() {
  int ret, fd;
  char msg[2048];
  char enc[2048];
  char dec[2048];
  fd = open("/dev/cry", O_RDWR);
  if (fd < 0) {
    perror("Could not open the device!");
    return errno;
  }
  printf("\nString that will be encrypted&decrypted: ");
  scanf("%[^\n]%*c", msg);
  int msgLen = strlen(msg);
  if (msgLen > 2048) {
    printf("Too long msg, maximum size is %d", 2048);
  }
  printf("\n");
  ret = write(fd, msg, msgLen);
  if (ret < 0) {
    perror("Could not send the string to the device!");
    close(fd);
    return errno;
  }
  ret = read(fd, enc, 2048);
  if (ret < 0) {
    perror("Could not read the binary from the device!");
    close(fd);
    return errno;
  }
  ret = write(fd, enc, msgLen);
  if (ret < 0) {
    perror("Could not send the string to the device!");
    close(fd);
    return errno;
  }
  ret = read(fd, dec, 2048);
  if (ret < 0) {
    perror("Could not read the string from the device!");
    close(fd);
    return errno;
  }
  print_buf(msg, msgLen, " <-- Original  message (HEX)");
  print_buf(enc, msgLen, " <-- Encrypted message (HEX)");
  print_buf(dec, msgLen, " <-- Decrypted message (HEX)");
  printf("%s <-- Original  message\n", msg);
  printf("%s <-- Encrypted message\n", enc);
  printf("%s <-- Decrypted message\n", dec);
  printf("\n");
  char buf[2048];
  ioctl(fd, 1, buf);
  printf("Current encryption key: %s\n", buf);
  printf("Setting new encryption key via IOCTL.\n");
  ioctl(fd, 0, "newKeyHere");
  ioctl(fd, 1, buf);
  printf("Current encryption key: %s\n\n", buf);
  ret = write(fd, msg, msgLen);
  if (ret < 0) {
    perror("Could not send the string to the device!");
    close(fd);
    return errno;
  }
  ret = read(fd, enc, 2048);
  if (ret < 0) {
    perror("Could not read the binary from the device!");
    close(fd);
    return errno;
  }
  ret = write(fd, enc, msgLen);
  if (ret < 0) {
    perror("Could not send the string to the device!");
    close(fd);
    return errno;
  }
  ret = read(fd, dec, 2048);
  if (ret < 0) {
    perror("Could not read the string from the device!");
    close(fd);
    return errno;
  }
  print_buf(msg, msgLen, " <-- Original  message (HEX)");
  print_buf(enc, msgLen, " <-- Encrypted message (HEX)");
  print_buf(dec, msgLen, " <-- Decrypted message (HEX)");
  printf("%s <-- Original  message\n", msg);
  printf("%s <-- Encrypted message\n", enc);
  printf("%s <-- Decrypted message\n", dec);
  printf("\n");
  ioctl(fd, 6);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11f1 <main+0x51>
lea    0xe2e(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x810(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x810(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1814(%rbp)
cmpl   $0x800,-0x1814(%rbp)
jle    1247 <main+0xa7>
lea    0xe1d(%rip),%rdi
mov    $0x800,%esi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xfb8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x1814(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    129c <main+0xfc>
lea    0xdfb(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x800,%edx
call   1090 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12e2 <main+0x142>
lea    0xdde(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x1814(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1329 <main+0x189>
lea    0xd6e(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1810(%rbp),%rsi
mov    $0x800,%edx
call   1090 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    136f <main+0x1cf>
lea    0xd7c(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
lea    -0x810(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xd75(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xd79(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x1810(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xd7d(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x810(%rbp),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1810(%rbp),%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x2020(%rbp),%rdx
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <ioctl@plt>
lea    -0x2020(%rbp),%rsi
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
lea    0xd94(%rip),%rdx
mov    $0x0,%al
call   1070 <ioctl@plt>
mov    -0xc(%rbp),%edi
lea    -0x2020(%rbp),%rdx
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <ioctl@plt>
lea    -0x2020(%rbp),%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x1814(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    14c5 <main+0x325>
lea    0xbd2(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2b1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x800,%edx
call   1090 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    150b <main+0x36b>
lea    0xbb5(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2ad7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x1814(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1552 <main+0x3b2>
lea    0xb45(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2a90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
mov    -0xc(%rbp),%edi
lea    -0x1810(%rbp),%rsi
mov    $0x800,%edx
call   1090 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1598 <main+0x3f8>
lea    0xb53(%rip),%rdi
call   10c0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2a4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    164e <main+0x4ae>
lea    -0x810(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xb4c(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xb50(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x1810(%rbp),%rdi
mov    -0x1814(%rbp),%esi
lea    0xb54(%rip),%rdx
call   1030 <print_buf@plt>
lea    -0x810(%rbp),%rsi
lea    0xb5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xb63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1810(%rbp),%rsi
lea    0xb68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xbdd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0x6,%esi
mov    $0x0,%al
call   1070 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     14c5 <main+0x305>
mov    %eax,%ebx
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe4c(%rip),%rdi
lea    0x1000(%rsp),%rbp
mov    %rbp,%rsi
call   10c0 <scanf@plt>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
cmp    $0x801,%eax
jl     1237 <main+0x77>
lea    0xe2d(%rip),%rdi
mov    $0x800,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1000(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1060 <write@plt>
test   %eax,%eax
js     1485 <main+0x2c5>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x800,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     148e <main+0x2ce>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1060 <write@plt>
test   %eax,%eax
js     1485 <main+0x2c5>
lea    0x800(%rsp),%rsi
mov    %ebx,%edi
mov    $0x800,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     1497 <main+0x2d7>
lea    0xe50(%rip),%rdx
lea    0x1000(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xe54(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xe5d(%rip),%rdx
lea    0x800(%rsp),%r12
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xe61(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe73(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1800(%rsp),%r15
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <ioctl@plt>
lea    0xe59(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe58(%rip),%rdx
mov    %ebx,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <ioctl@plt>
lea    0xe40(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <write@plt>
test   %eax,%eax
js     1485 <main+0x2c5>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x800,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     148e <main+0x2ce>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1060 <write@plt>
test   %eax,%eax
js     1485 <main+0x2c5>
lea    0x800(%rsp),%rsi
mov    %ebx,%edi
mov    $0x800,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     1497 <main+0x2d7>
lea    0xd08(%rip),%rdx
lea    0x1000(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xd0c(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xd15(%rip),%rdx
lea    0x800(%rsp),%r12
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <print_buf@plt>
lea    0xd19(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd20(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd29(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
mov    $0x6,%esi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    14b3 <main+0x2f3>
lea    0xbed(%rip),%rdi
jmp    149e <main+0x2de>
lea    0xc0d(%rip),%rdi
jmp    149e <main+0x2de>
lea    0xc2f(%rip),%rdi
call   10e0 <perror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb3d(%rip),%rdi
call   10e0 <perror@plt>
jmp    14aa <main+0x2ea>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/cry\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Could not open the device!\00"
@errno = global i32 0
@.str.2 = [43 x i8] c"\0AString that will be encrypted&decrypted: \00"
@.str.3 = [9 x i8] c"%[^\0A]%*c\00"
@.str.4 = [33 x i8] c"Too long msg, maximum size is %d\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [41 x i8] c"Could not send the string to the device!\00"
@.str.7 = [43 x i8] c"Could not read the binary from the device!\00"
@.str.8 = [43 x i8] c"Could not read the string from the device!\00"
@.str.9 = [29 x i8] c" <-- Original message (HEX)\00"
@.str.10 = [29 x i8] c" <-- Encrypted message (HEX)\00"
@.str.11 = [29 x i8] c" <-- Decrypted message (HEX)\00"
@.str.12 = [26 x i8] c"%s <-- Original message\0A\00"
@.str.13 = [26 x i8] c"%s <-- Encrypted message\0A\00"
@.str.14 = [26 x i8] c"%s <-- Decrypted message\0A\00"
@.str.15 = [28 x i8] c"Current encryption key: %s\0A\00"
@.str.16 = [39 x i8] c"Setting new encryption key via IOCTL.\0A\00"
@.str.17 = [11 x i8] c"newKeyHere\00"
@.str.18 = [29 x i8] c"Current encryption key: %s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = alloca [2048 x i8]
%7 = alloca i32
%8 = alloca [2048 x i8]
store i32 0, i32* %1
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @errno
store i32 %15, i32* %1
br label %169
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%19 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 2048
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 2048)
br label %26
26: ; preds = %24, %16
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @errno
store i32 %38, i32* %1
br label %169
39: ; preds = %26
%40 = load i32, i32* %3
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 2048)
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* @errno
store i32 %49, i32* %1
br label %169
50: ; preds = %39
%51 = load i32, i32* %3
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%53 = load i32, i32* %7
%54 = call i32 @write(i32 %51, i8* %52, i32 %53)
store i32 %54, i32* %2
%55 = load i32, i32* %2
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %50
%58 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%59 = load i32, i32* %3
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* @errno
store i32 %61, i32* %1
br label %169
62: ; preds = %50
%63 = load i32, i32* %3
%64 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 2048)
store i32 %65, i32* %2
%66 = load i32, i32* %2
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%70 = load i32, i32* %3
%71 = call i32 @close(i32 %70)
%72 = load i32, i32* @errno
store i32 %72, i32* %1
br label %169
73: ; preds = %62
%74 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%75 = load i32, i32* %7
%76 = call i32 @print_buf(i8* %74, i32 %75, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%77 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%78 = load i32, i32* %7
%79 = call i32 @print_buf(i8* %77, i32 %78, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%80 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%81 = load i32, i32* %7
%82 = call i32 @print_buf(i8* %80, i32 %81, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%83 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %83)
%85 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %85)
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0), i8* %87)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%90 = load i32, i32* %3
%91 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%92 = call i32 (i32, i32, ...) @ioctl(i32 %90, i32 1, i8* %91)
%93 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i8* %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.16, i64 0, i64 0))
%96 = load i32, i32* %3
%97 = call i32 (i32, i32, ...) @ioctl(i32 %96, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0))
%98 = load i32, i32* %3
%99 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%100 = call i32 (i32, i32, ...) @ioctl(i32 %98, i32 1, i8* %99)
%101 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i8* %101)
%103 = load i32, i32* %3
%104 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%105 = load i32, i32* %7
%106 = call i32 @write(i32 %103, i8* %104, i32 %105)
store i32 %106, i32* %2
%107 = load i32, i32* %2
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %114
109: ; preds = %73
%110 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%111 = load i32, i32* %3
%112 = call i32 @close(i32 %111)
%113 = load i32, i32* @errno
store i32 %113, i32* %1
br label %169
114: ; preds = %73
%115 = load i32, i32* %3
%116 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%117 = call i32 @read(i32 %115, i8* %116, i32 2048)
store i32 %117, i32* %2
%118 = load i32, i32* %2
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %125
120: ; preds = %114
%121 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%122 = load i32, i32* %3
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* @errno
store i32 %124, i32* %1
br label %169
125: ; preds = %114
%126 = load i32, i32* %3
%127 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%128 = load i32, i32* %7
%129 = call i32 @write(i32 %126, i8* %127, i32 %128)
store i32 %129, i32* %2
%130 = load i32, i32* %2
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %137
132: ; preds = %125
%133 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%134 = load i32, i32* %3
%135 = call i32 @close(i32 %134)
%136 = load i32, i32* @errno
store i32 %136, i32* %1
br label %169
137: ; preds = %125
%138 = load i32, i32* %3
%139 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%140 = call i32 @read(i32 %138, i8* %139, i32 2048)
store i32 %140, i32* %2
%141 = load i32, i32* %2
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %148
143: ; preds = %137
%144 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%145 = load i32, i32* %3
%146 = call i32 @close(i32 %145)
%147 = load i32, i32* @errno
store i32 %147, i32* %1
br label %169
148: ; preds = %137
%149 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%150 = load i32, i32* %7
%151 = call i32 @print_buf(i8* %149, i32 %150, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%152 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%153 = load i32, i32* %7
%154 = call i32 @print_buf(i8* %152, i32 %153, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%155 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%156 = load i32, i32* %7
%157 = call i32 @print_buf(i8* %155, i32 %156, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%158 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %158)
%160 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %160)
%162 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0), i8* %162)
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%165 = load i32, i32* %3
%166 = call i32 (i32, i32, ...) @ioctl(i32 %165, i32 6)
%167 = load i32, i32* %3
%168 = call i32 @close(i32 %167)
store i32 0, i32* %1
br label %169
169: ; preds = %148, %143, %132, %120, %109, %68, %57, %45, %34, %13
%170 = load i32, i32* %1
ret i32 %170
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/cry\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Could not open the device!\00"
@errno = global i32 0
@.str.2 = [43 x i8] c"\0AString that will be encrypted&decrypted: \00"
@.str.3 = [9 x i8] c"%[^\0A]%*c\00"
@.str.4 = [33 x i8] c"Too long msg, maximum size is %d\00"
@.str.6 = [41 x i8] c"Could not send the string to the device!\00"
@.str.7 = [43 x i8] c"Could not read the binary from the device!\00"
@.str.8 = [43 x i8] c"Could not read the string from the device!\00"
@.str.9 = [29 x i8] c" <-- Original message (HEX)\00"
@.str.10 = [29 x i8] c" <-- Encrypted message (HEX)\00"
@.str.11 = [29 x i8] c" <-- Decrypted message (HEX)\00"
@.str.12 = [26 x i8] c"%s <-- Original message\0A\00"
@.str.13 = [26 x i8] c"%s <-- Encrypted message\0A\00"
@.str.14 = [26 x i8] c"%s <-- Decrypted message\0A\00"
@.str.15 = [28 x i8] c"Current encryption key: %s\0A\00"
@.str.17 = [11 x i8] c"newKeyHere\00"
@.str.18 = [29 x i8] c"Current encryption key: %s\0A\0A\00"
@str = [38 x i8] c"Setting new encryption key via IOCTL.\00"
define i32 @main() {
%1 = alloca [2048 x i8]
%2 = alloca [2048 x i8]
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @errno
br label %104
14: ; preds = %0
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%17 = call i32 @strlen(i8* %5)
%18 = icmp sgt i32 %17, 2048
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 2048)
br label %21
21: ; preds = %19, %14
%22 = call i32 @putchar(i32 10)
%23 = call i32 @write(i32 %9, i8* %5, i32 %17)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @close(i32 %9)
%28 = load i32, i32* @errno
br label %104
29: ; preds = %21
%30 = call i32 @read(i32 %9, i8* %6, i32 2048)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @close(i32 %9)
%35 = load i32, i32* @errno
br label %104
36: ; preds = %29
%37 = call i32 @write(i32 %9, i8* %6, i32 %17)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @close(i32 %9)
%42 = load i32, i32* @errno
br label %104
43: ; preds = %36
%44 = call i32 @read(i32 %9, i8* %7, i32 2048)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%48 = call i32 @close(i32 %9)
%49 = load i32, i32* @errno
br label %104
50: ; preds = %43
%51 = call i32 @print_buf(i8* %5, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%52 = call i32 @print_buf(i8* %6, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%53 = call i32 @print_buf(i8* %7, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %5)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %6)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0), i8* %7)
%57 = call i32 @putchar(i32 10)
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%59 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 1, i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0), i8* %58)
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%62 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0))
%63 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 1, i8* %58)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i8* %58)
%65 = call i32 @write(i32 %9, i8* %5, i32 %17)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %50
%68 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @close(i32 %9)
%70 = load i32, i32* @errno
br label %102
71: ; preds = %50
%72 = call i32 @read(i32 %9, i8* %6, i32 2048)
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%76 = call i32 @close(i32 %9)
%77 = load i32, i32* @errno
br label %102
78: ; preds = %71
%79 = call i32 @write(i32 %9, i8* %6, i32 %17)
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @close(i32 %9)
%84 = load i32, i32* @errno
br label %102
85: ; preds = %78
%86 = call i32 @read(i32 %9, i8* %7, i32 2048)
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 @close(i32 %9)
%91 = load i32, i32* @errno
br label %102
92: ; preds = %85
%93 = call i32 @print_buf(i8* %5, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%94 = call i32 @print_buf(i8* %6, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%95 = call i32 @print_buf(i8* %7, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %5)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %6)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0), i8* %7)
%99 = call i32 @putchar(i32 10)
%100 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 6)
%101 = call i32 @close(i32 %9)
br label %102
102: ; preds = %92, %88, %81, %74, %67
%103 = phi i32 [ %70, %67 ], [ %77, %74 ], [ %84, %81 ], [ %91, %88 ], [ 0, %92 ]
br label %104
104: ; preds = %25, %32, %39, %46, %102, %11
%105 = phi i32 [ %13, %11 ], [ %28, %25 ], [ %35, %32 ], [ %42, %39 ], [ %49, %46 ], [ %103, %102 ]
ret i32 %105
}