#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ read();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int tell();
int main(void) {
  int x;
  char *answer;
  if ((answer = malloc(21 * (sizeof(char)))) == NULL) {
    fprintf(stderr, "Not enough space, shutting down programm.\n");
    return -1;
  }
  printf("Do you want to read a joke or to tell me one?\n(answer with 'read' "
         "or 'tell', type exit for the obvious reason)\n");
  fgets(answer, 6, stdin);
  while (0 != strcmp(answer, "exit\n")) {
    if (0 == strcmp(answer, "read\n")) {
      fprintf(stderr, "Let me choose one, hit Enter when ready to laugh :P\n");
      getchar();
      if (read()) {
        fprintf(stderr, "I found no jokes!! Pls update me :P\n");
      }
    } else if (0 == strcmp(answer, "tell\n")) {
      fprintf(stderr, "Okie dokie, go on then :D\n");
      if (tell() == 1) {
        fprintf(stderr, "No space available buddy...\n");
      }
      fprintf(stderr, "Hahahahaha, nice one! :D\n");
    } else {
      fprintf(stderr, "Please select a valid choice:\n");
    }
    fprintf(
        stderr,
        "(answer with 'read' or 'tell', type exit for the obvious reason)\n");
    fgets(answer, 6, stdin);
  }
  free(answer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x15,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d8 <main+0x48>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134b <main+0x1bb>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     133b <main+0x1ab>
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    127e <main+0xee>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
je     1279 <main+0xe9>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1090 <fprintf@plt>
jmp    130a <main+0x17a>
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12f0 <main+0x160>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x0,%al
call   10a0 <tell@plt>
cmp    $0x1,%eax
jne    12d6 <main+0x146>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1305 <main+0x175>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1090 <fprintf@plt>
jmp    130a <main+0x17a>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1060 <fgets@plt>
jmp    11fb <main+0x6b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x15,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     12f3 <main+0x163>
mov    %rax,%rbx
lea    0xf92(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e24(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1060 <fgets@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e7 <main+0x157>
lea    0xe3e(%rip),%r14
mov    0x2dde(%rip),%r12
lea    0xf07(%rip),%r13
lea    0xe23(%rip),%rbp
jmp    124c <main+0xbc>
nopw   0x0(%rax,%rax,1)
lea    0xed2(%rip),%rsi
call   1090 <fprintf@plt>
mov    (%r12),%edi
mov    %r13,%rsi
call   1090 <fprintf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e7 <main+0x157>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b0 <main+0x120>
mov    %rbx,%rdi
lea    0xe2b(%rip),%rsi
call   1070 <strcmp@plt>
mov    (%r12),%edi
test   %rax,%rax
jne    1210 <main+0x80>
lea    0xe1c(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
call   10a0 <tell@plt>
cmp    $0x1,%eax
jne    129c <main+0x10c>
mov    (%r12),%edi
lea    0xe1b(%rip),%rsi
call   1090 <fprintf@plt>
mov    (%r12),%edi
lea    0xe28(%rip),%rsi
jmp    1217 <main+0x87>
nopl   0x0(%rax)
mov    (%r12),%edi
lea    0xd7c(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
je     121c <main+0x8c>
mov    (%r12),%edi
lea    0xd8a(%rip),%rsi
jmp    1217 <main+0x87>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    130d <main+0x17d>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Not enough space, shutting down programm.\0A\00"
@.str.1 = [112 x i8] c"Do you want to read a joke or to tell me one?\0A(answer with 'read' or 'tell', type exit for the obvious reason)\0A\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"exit\0A\00"
@.str.3 = [6 x i8] c"read\0A\00"
@.str.4 = [53 x i8] c"Let me choose one, hit Enter when ready to laugh :P\0A\00"
@.str.5 = [37 x i8] c"I found no jokes!! Pls update me :P\0A\00"
@.str.6 = [6 x i8] c"tell\0A\00"
@.str.7 = [27 x i8] c"Okie dokie, go on then :D\0A\00"
@.str.8 = [29 x i8] c"No space available buddy...\0A\00"
@.str.9 = [26 x i8] c"Hahahahaha, nice one! :D\0A\00"
@.str.10 = [31 x i8] c"Please select a valid choice:\0A\00"
@.str.11 = [66 x i8] c"(answer with 'read' or 'tell', type exit for the obvious reason)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @malloc(i32 21)
store i8* %4, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %60
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 6, i32 %12)
br label %14
14: ; preds = %51, %9
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 0, %16
br i1 %17, label %18, label %57
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 0, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 (...) @getchar()
%26 = call i64 (...) @read()
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %28, %22
br label %51
32: ; preds = %18
%33 = load i8*, i8** %3
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp eq i64 0, %34
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 (...) @tell()
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %50
47: ; preds = %32
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %31
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.11, i64 0, i64 0))
%54 = load i8*, i8** %3
%55 = load i32, i32* @stdin
%56 = call i32 @fgets(i8* %54, i32 6, i32 %55)
br label %14
57: ; preds = %14
%58 = load i8*, i8** %3
%59 = call i32 @free(i8* %58)
store i32 0, i32* %1
br label %60
60: ; preds = %57, %6
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Not enough space, shutting down programm.\0A\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"exit\0A\00"
@.str.3 = [6 x i8] c"read\0A\00"
@.str.4 = [53 x i8] c"Let me choose one, hit Enter when ready to laugh :P\0A\00"
@.str.5 = [37 x i8] c"I found no jokes!! Pls update me :P\0A\00"
@.str.6 = [6 x i8] c"tell\0A\00"
@.str.7 = [27 x i8] c"Okie dokie, go on then :D\0A\00"
@.str.8 = [29 x i8] c"No space available buddy...\0A\00"
@.str.9 = [26 x i8] c"Hahahahaha, nice one! :D\0A\00"
@.str.10 = [31 x i8] c"Please select a valid choice:\0A\00"
@.str.11 = [66 x i8] c"(answer with 'read' or 'tell', type exit for the obvious reason)\0A\00"
@str = [111 x i8] c"Do you want to read a joke or to tell me one?\0A(answer with 'read' or 'tell', type exit for the obvious reason)\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(21) i8* @malloc(i32 21)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %49
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([111 x i8], [111 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgets(i8* %1, i32 6, i32 %8)
%10 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %47, label %12
12: ; preds = %6, %40
%13 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 (...) @getchar()
%19 = tail call i64 (...) @read()
%20 = icmp eq i64 %19, 0
br i1 %20, label %40, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %40
24: ; preds = %12
%25 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = load i32, i32* @stderr
br i1 %26, label %28, label %38
28: ; preds = %24
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%30 = tail call i32 (...) @tell()
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %35
35: ; preds = %32, %28
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %40
38: ; preds = %24
%39 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0))
br label %40
40: ; preds = %35, %38, %15, %21
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.11, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = tail call i32 @fgets(i8* %1, i32 6, i32 %43)
%45 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %12
47: ; preds = %40, %6
%48 = tail call i32 @free(i8* %1)
br label %49
49: ; preds = %47, %3
%50 = phi i32 [ -1, %3 ], [ 0, %47 ]
ret i32 %50
}