#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 */
scalar_t__ nactiKlic(char *);
scalar_t__ nactiZpravu();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ vypisKlic();
int /*<<< orphan*/ vypisZpravu();
int /*<<< orphan*/ zasifruj();
int main(int argc, char **argv) {
  if (argc != 1 && argc != 3) {
    printf("USAGE: \n"
           "   %s [ -k KEY ]\n"
           "\n"
           "      KEY   80-bit klic v hexa zapisu\n"
           "            vychozi hodnota je 00 00 00 00 00 00 00 00 00 00\n    "
           "\n"
           "      Program cte zpravu ze stdin o velikost 64 bitu (1 blok)    n"
           "      v hexa zapisu\n"
           "\n"
           "EXAMPLE\n"
           "   echo \"FF FF FF FF FF FF FF FF\" | %s \n"
           "   echo \"FF FF FF FF FF FF FF FF\" | %s -k \"FF FF FF FF FF F    "
           "F FF FF FF FF\""
           "\n",
           argv[0], argv[0], argv[0]);
    return 1;
  }
  if (argc == 3) {
    if (strncmp("-k", argv[1], sizeof("-k")) == 0) {
      if (nactiKlic(argv[2]) != 0) {
        return 2;
      }
    } else {
      printf("Chybny prepinac\n");
      return 2;
    }
  }
  if (nactiZpravu() != 0) {
    return 3;
  }
  printf("hello PRESENT!\n");
  printf("Zprava k sifrovani: ");
  vypisZpravu();
  printf("Sifruji klicem:     ");
  vypisKlic();
  zasifruj();
  printf("Ciphertext:         ");
  vypisZpravu();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11c9 <main+0x59>
cmpl   $0x3,-0x8(%rbp)
je     11c9 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <main+0x145>
cmpl   $0x3,-0x8(%rbp)
jne    123d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xf76(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <nactiKlic@plt>
cmp    $0x0,%rax
je     1219 <main+0xa9>
movl   $0x2,-0x4(%rbp)
jmp    12b5 <main+0x145>
jmp    1238 <main+0xc8>
lea    0xf36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12b5 <main+0x145>
jmp    123d <main+0xcd>
mov    $0x0,%al
call   1070 <nactiZpravu@plt>
cmp    $0x0,%rax
je     125a <main+0xea>
movl   $0x3,-0x4(%rbp)
jmp    12b5 <main+0x145>
lea    0xf0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xf0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <vypisZpravu@plt>
lea    0xf0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1050 <vypisKlic@plt>
mov    $0x0,%al
call   1090 <zasifruj@plt>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <vypisZpravu@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0x1,%eax
jne    11c0 <main+0x40>
cmp    $0x3,%edi
jne    11f6 <main+0x76>
mov    0x8(%rbx),%rsi
lea    0xfba(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11de <main+0x5e>
lea    0xff5(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2,%eax
pop    %rbx
ret
mov    (%rbx),%rcx
lea    0xe36(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x10(%rbx),%rdi
call   1090 <nactiKlic@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
je     11f6 <main+0x76>
pop    %rbx
ret
xor    %eax,%eax
call   1080 <nactiZpravu@plt>
mov    %rax,%rcx
mov    $0x3,%eax
test   %rcx,%rcx
jne    11f4 <main+0x74>
lea    0xf89(%rip),%rdi
call   1050 <puts@plt>
lea    0xf3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <vypisZpravu@plt>
lea    0xf3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1060 <vypisKlic@plt>
xor    %eax,%eax
call   10a0 <zasifruj@plt>
lea    0xf37(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <vypisZpravu@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [344 x i8] c"USAGE: \0A %s [ -k KEY ]\0A\0A KEY 80-bit klic v hexa zapisu\0A vychozi hodnota je 00 00 00 00 00 00 00 00 00 00\0A \0A Program cte zpravu ze stdin o velikost 64 bitu (1 blok) n v hexa zapisu\0A\0AEXAMPLE\0A echo \22FF FF FF FF FF FF FF FF\22 | %s \0A echo \22FF FF FF FF FF FF FF FF\22 | %s -k \22FF FF FF FF FF F F FF FF FF FF\22\0A\00"
@.str.1 = [3 x i8] c"-k\00"
@.str.2 = [17 x i8] c"Chybny prepinac\0A\00"
@.str.3 = [16 x i8] c"hello PRESENT!\0A\00"
@.str.4 = [21 x i8] c"Zprava k sifrovani: \00"
@.str.5 = [21 x i8] c"Sifruji klicem: \00"
@.str.6 = [21 x i8] c"Ciphertext: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([344 x i8], [344 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %17, i8* %20)
store i32 1, i32* %3
br label %55
22: ; preds = %8, %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %42
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @nactiKlic(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 2, i32* %3
br label %55
38: ; preds = %31
br label %41
39: ; preds = %25
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %55
41: ; preds = %38
br label %42
42: ; preds = %41, %22
%43 = call i64 (...) @nactiZpravu()
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 3, i32* %3
br label %55
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 (...) @vypisZpravu()
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 (...) @vypisKlic()
%52 = call i32 (...) @zasifruj()
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 (...) @vypisZpravu()
store i32 0, i32* %3
br label %55
55: ; preds = %46, %45, %39, %37, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [344 x i8] c"USAGE: \0A %s [ -k KEY ]\0A\0A KEY 80-bit klic v hexa zapisu\0A vychozi hodnota je 00 00 00 00 00 00 00 00 00 00\0A \0A Program cte zpravu ze stdin o velikost 64 bitu (1 blok) n v hexa zapisu\0A\0AEXAMPLE\0A echo \22FF FF FF FF FF FF FF FF\22 | %s \0A echo \22FF FF FF FF FF FF FF FF\22 | %s -k \22FF FF FF FF FF F F FF FF FF FF\22\0A\00"
@.str.1 = [3 x i8] c"-k\00"
@.str.4 = [21 x i8] c"Zprava k sifrovani: \00"
@.str.5 = [21 x i8] c"Sifruji klicem: \00"
@.str.6 = [21 x i8] c"Ciphertext: \00"
@str = [15 x i8] c"hello PRESENT!\00"
@str.7 = [16 x i8] c"Chybny prepinac\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -3
%4 = icmp eq i32 %3, 1
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([344 x i8], [344 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %6, i8* %6)
br label %34
8: ; preds = %2
%9 = icmp eq i32 %0, 3
br i1 %9, label %10, label %22
10: ; preds = %8
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @nactiKlic(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %34
20: ; preds = %10
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %34
22: ; preds = %15, %8
%23 = tail call i64 (...) @nactiZpravu()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%28 = tail call i32 (...) @vypisZpravu()
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i32 (...) @vypisKlic()
%31 = tail call i32 (...) @zasifruj()
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%33 = tail call i32 (...) @vypisZpravu()
br label %34
34: ; preds = %22, %15, %25, %20, %5
%35 = phi i32 [ 1, %5 ], [ 0, %25 ], [ 2, %20 ], [ 2, %15 ], [ 3, %22 ]
ret i32 %35
}