#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 between(int, int /*<<< orphan*/, int);
char getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ *strcpy(char *, char *);
int strlen(char *);
void priklad_dva() {
  printf("========== PRIKLAD 2 ==========\n");
  char str1[50], str2[50], str3[50], zn;
  char *ukStr = NULL;
  int porovnej = 0;
  printf("Zadejte STR1: ");
  gets(str1);
  printf("Zadejte STR2: ");
  gets(str2);
  printf("STR1= %d  STR2= %d\n", strlen(str1), strlen(str2));
  *strcpy(str3, str2);
  *strcat(str1, str3);
  printf("STR1+3= ");
  puts(str1);
  printf("Zadejte ZN: ");
  zn = getchar();
  for (int i = 0; i < strlen(str1); i++) {
    if (str1[i] == zn) {
      ukStr = &str1[i];
      break;
    }
  }
  if (ukStr == NULL) {
    printf("Hledany znak nebyl nalezen.");
  } else {
    printf("Hledany znak je na indexu %d.\n", ukStr - &str1[0]);
  }
  porovnej = between(-1, strcmp(str1, str2), 1);
  switch (porovnej) {
  case 0:
    printf("STR1 = STR2\n");
    break;
  case 1:
    printf("STR1 > STR2\n");
    break;
  case -1:
    printf("STR1 < STR2\n");
    break;
  }
  printf("========== KONEC PRIKLADU 2 ==========\n");
}


x86 assembly (clang, -O0):
<priklad_dva>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0xd0(%rbp)
movl   $0x0,-0xd4(%rbp)
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1090 <gets@plt>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1090 <gets@plt>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xdc(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xdc(%rbp),%esi
mov    %eax,%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   10a0 <strcat@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0xc1(%rbp)
movl   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
mov    %eax,-0xe0(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xe0(%rbp),%eax
cmp    %ecx,%eax
jge    12e9 <priklad_dva+0x159>
movslq -0xd8(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
movsbl -0xc1(%rbp),%ecx
cmp    %ecx,%eax
jne    12d0 <priklad_dva+0x140>
movslq -0xd8(%rbp),%rcx
lea    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xd0(%rbp)
jmp    12e9 <priklad_dva+0x159>
jmp    12d5 <priklad_dva+0x145>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    1276 <priklad_dva+0xe6>
cmpq   $0x0,-0xd0(%rbp)
jne    130a <priklad_dva+0x17a>
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1326 <priklad_dva+0x196>
mov    -0xd0(%rbp),%rsi
lea    -0x40(%rbp),%rax
sub    %rax,%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %eax,%esi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   10b0 <between@plt>
mov    %eax,-0xd4(%rbp)
mov    -0xd4(%rbp),%eax
mov    %eax,-0xe4(%rbp)
sub    $0xffffffff,%eax
je     13b1 <priklad_dva+0x221>
jmp    1364 <priklad_dva+0x1d4>
mov    -0xe4(%rbp),%eax
test   %eax,%eax
je     138b <priklad_dva+0x1fb>
jmp    1377 <priklad_dva+0x1e7>
mov    -0xe4(%rbp),%eax
sub    $0x1,%eax
je     139e <priklad_dva+0x20e>
jmp    13bf <priklad_dva+0x22f>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13bf <priklad_dva+0x22f>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13bf <priklad_dva+0x22f>
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priklad_dva>:
push   %rbp
push   %r14
push   %rbx
sub    $0xc0,%rsp
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1090 <gets@plt>
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe2a(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <strcat@plt>
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1279 <priklad_dva+0xe9>
xor    %ebx,%ebx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
cmp    %bpl,(%rsp,%rbx,1)
je     1289 <priklad_dva+0xf9>
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1260 <priklad_dva+0xd0>
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    129a <priklad_dva+0x10a>
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rdi
lea    0x40(%rsp),%rsi
call   1070 <strcmp@plt>
mov    $0xffffffff,%edi
mov    %eax,%esi
mov    $0x1,%edx
call   10b0 <between@plt>
add    $0x1,%eax
cmp    $0x2,%eax
ja     12d5 <priklad_dva+0x145>
cltq
lea    0xe27(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1040 <puts@plt>
lea    0xdd3(%rip),%rdi
call   1040 <puts@plt>
add    $0xc0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"========== PRIKLAD 2 ==========\0A\00"
@.str.1 = [15 x i8] c"Zadejte STR1: \00"
@.str.2 = [15 x i8] c"Zadejte STR2: \00"
@.str.3 = [20 x i8] c"STR1= %d STR2= %d\0A\00"
@.str.4 = [9 x i8] c"STR1+3= \00"
@.str.5 = [13 x i8] c"Zadejte ZN: \00"
@.str.6 = [28 x i8] c"Hledany znak nebyl nalezen.\00"
@.str.7 = [31 x i8] c"Hledany znak je na indexu %d.\0A\00"
@.str.8 = [13 x i8] c"STR1 = STR2\0A\00"
@.str.9 = [13 x i8] c"STR1 > STR2\0A\00"
@.str.10 = [13 x i8] c"STR1 < STR2\0A\00"
@.str.11 = [40 x i8] c"========== KONEC PRIKLADU 2 ==========\0A\00"
define void @priklad_dva() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %18)
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%22 = call i32* @strcpy(i8* %20, i8* %21)
%23 = load i32, i32* %22
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%26 = call i32* @strcat(i8* %24, i8* %25)
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%30 = call i32 @puts(i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%32 = call signext i8 (...) @getchar()
store i8 %32, i8* %4
store i32 0, i32* %7
br label %33
33: ; preds = %52, %0
%34 = load i32, i32* %7
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %55
38: ; preds = %33
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i8, i8* %4
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %43, %45
br i1 %46, label %47, label %51
47: ; preds = %38
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %49
store i8* %50, i8** %5
br label %55
51: ; preds = %38
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %33
55: ; preds = %47, %33
%56 = load i8*, i8** %5
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %67
60: ; preds = %55
%61 = load i8*, i8** %5
%62 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%63 = ptrtoint i8* %61 to i64
%64 = ptrtoint i8* %62 to i64
%65 = sub i64 %63, %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64 %65)
br label %67
67: ; preds = %60, %58
%68 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%70 = call i32 @strcmp(i8* %68, i8* %69)
%71 = call i32 @between(i32 -1, i32 %70, i32 1)
store i32 %71, i32* %6
%72 = load i32, i32* %6
switch i32 %72, label %79 [
i32 0, label %73
i32 1, label %75
i32 -1, label %77
]
73: ; preds = %67
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %79
75: ; preds = %67
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %79
77: ; preds = %67
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %79
79: ; preds = %67, %77, %75, %73
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Zadejte STR1: \00"
@.str.2 = [15 x i8] c"Zadejte STR2: \00"
@.str.3 = [20 x i8] c"STR1= %d STR2= %d\0A\00"
@.str.4 = [9 x i8] c"STR1+3= \00"
@.str.5 = [13 x i8] c"Zadejte ZN: \00"
@.str.6 = [28 x i8] c"Hledany znak nebyl nalezen.\00"
@.str.7 = [31 x i8] c"Hledany znak je na indexu %d.\0A\00"
@str = [32 x i8] c"========== PRIKLAD 2 ==========\00"
@str.12 = [12 x i8] c"STR1 < STR2\00"
@str.13 = [39 x i8] c"========== KONEC PRIKLADU 2 ==========\00"
@str.14 = [12 x i8] c"STR1 > STR2\00"
@str.15 = [12 x i8] c"STR1 = STR2\00"
@reltable.priklad_dva = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.12 to i64), i64 ptrtoint ([3 x i32]* @reltable.priklad_dva to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.15 to i64), i64 ptrtoint ([3 x i32]* @reltable.priklad_dva to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.14 to i64), i64 ptrtoint ([3 x i32]* @reltable.priklad_dva to i64)) to i32)]
define void @priklad_dva() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @gets(i8* %5)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @gets(i8* %6)
%12 = call i32 @strlen(i8* %5)
%13 = call i32 @strlen(i8* %6)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32* @strcpy(i8* %7, i8* %6)
%16 = call i32* @strcat(i8* %5, i8* %7)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @puts(i8* %5)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%20 = call signext i8 (...) @getchar()
%21 = call i32 @strlen(i8* %5)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %0, %28
%24 = phi i64 [ %29, %28 ], [ 0, %0 ]
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, %20
br i1 %27, label %35, label %28
28: ; preds = %23
%29 = add nuw nsw i64 %24, 1
%30 = call i32 @strlen(i8* %5)
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %23, label %33
33: ; preds = %28, %0
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %38
35: ; preds = %23
%36 = and i64 %24, 4294967295
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %35, %33
%39 = call i32 @strcmp(i8* %5, i8* %6)
%40 = call i32 @between(i32 -1, i32 %39, i32 1)
%41 = add i32 %40, 1
%42 = icmp ult i32 %41, 3
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = sext i32 %41 to i64
%45 = shl i64 %44, 2
%46 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.priklad_dva to i8*), i64 %45)
%47 = call i32 @puts(i8* dereferenceable(1) %46)
br label %48
48: ; preds = %38, %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
ret void
}