#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*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
char *strtok(char *, char *);
int readAndDisplayBookInformation(const char *path) {
  char line[(80)];
  FILE *fr = fopen(path, "rt");
  char *token;
  int counter = 0;
  int length;
  while (fgets(line, (80), fr) != NULL) {
    length = strlen(line);
    line[length - 1] = 0;
    token = strtok(line, ",");
    counter = 0;
    while (token) {
      switch (counter++) {
      case 0:
        printf("\"%s\" by", token);
        break;
      case 1:
        printf(" %s", token);
        break;
      case 2:
        printf(" (%s)", token);
        break;
      default:
        assert(!"not supported phrase!");
        break;
      }
      token = strtok(NULL, ",");
    }
    printf("\n");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<readAndDisplayBookInformation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     129a <readAndDisplayBookInformation+0x13a>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1287 <readAndDisplayBookInformation+0x127>
mov    -0x74(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x74(%rbp)
test   %eax,%eax
je     1222 <readAndDisplayBookInformation+0xc2>
jmp    1200 <readAndDisplayBookInformation+0xa0>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
je     1239 <readAndDisplayBookInformation+0xd9>
jmp    1211 <readAndDisplayBookInformation+0xb1>
mov    -0x7c(%rbp),%eax
sub    $0x2,%eax
je     1250 <readAndDisplayBookInformation+0xf0>
jmp    1267 <readAndDisplayBookInformation+0x107>
mov    -0x70(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126e <readAndDisplayBookInformation+0x10e>
mov    -0x70(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126e <readAndDisplayBookInformation+0x10e>
mov    -0x70(%rbp),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126e <readAndDisplayBookInformation+0x10e>
xor    %edi,%edi
call   1060 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd8a(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x70(%rbp)
jmp    11da <readAndDisplayBookInformation+0x7a>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118a <readAndDisplayBookInformation+0x2a>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAndDisplayBookInformation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x50,%esi
mov    %rax,0x8(%rsp)
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1279 <readAndDisplayBookInformation+0x109>
lea    0xe4f(%rip),%rbx
lea    0xe56(%rip),%r12
lea    0xe4b(%rip),%r13
lea    0xe3c(%rip),%rbp
jmp    11f5 <readAndDisplayBookInformation+0x85>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    0x8(%rsp),%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1279 <readAndDisplayBookInformation+0x109>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     11d0 <readAndDisplayBookInformation+0x60>
xor    %r14d,%r14d
jmp    1240 <readAndDisplayBookInformation+0xd0>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
add    $0x1,%r14d
test   %rax,%rax
je     11d0 <readAndDisplayBookInformation+0x60>
cmp    $0x2,%r14d
je     1260 <readAndDisplayBookInformation+0xf0>
cmp    $0x1,%r14d
je     1220 <readAndDisplayBookInformation+0xb0>
test   %r14d,%r14d
jne    1270 <readAndDisplayBookInformation+0x100>
mov    %rbp,%rdi
jmp    1223 <readAndDisplayBookInformation+0xb3>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
jmp    1223 <readAndDisplayBookInformation+0xb3>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
call   1070 <assert@plt>
jmp    122d <readAndDisplayBookInformation+0xbd>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [8 x i8] c"\22%s\22 by\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [6 x i8] c" (%s)\00"
@.str.5 = [22 x i8] c"not supported phrase!\00"
@.str.6 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @readAndDisplayBookInformation(i8* %0) {
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
store i32 0, i32* %6
br label %10
10: ; preds = %43, %1
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32* @fgets(i8* %11, i32 80, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%23 = call i8* @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %5
store i32 0, i32* %6
br label %24
24: ; preds = %41, %15
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
switch i32 %28, label %39 [
i32 0, label %30
i32 1, label %33
i32 2, label %36
]
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %41
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %41
36: ; preds = %27
%37 = load i8*, i8** %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %41
39: ; preds = %27
%40 = call i32 @assert(i32 0)
br label %41
41: ; preds = %39, %36, %33, %30
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %42, i8** %5
br label %24
43: ; preds = %24
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %10
45: ; preds = %10
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [8 x i8] c"\22%s\22 by\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [6 x i8] c" (%s)\00"
@EXIT_SUCCESS = global i32 0
define i32 @readAndDisplayBookInformation(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %33, label %7
7: ; preds = %1, %29
%8 = call i32 @strlen(i8* %3)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %29, label %14
14: ; preds = %7, %26
%15 = phi i8* [ %27, %26 ], [ %12, %7 ]
%16 = phi i32 [ %17, %26 ], [ 0, %7 ]
%17 = add nuw nsw i32 %16, 1
switch i32 %16, label %24 [
i32 0, label %18
i32 1, label %20
i32 2, label %22
]
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %26
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %26
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %26
24: ; preds = %14
%25 = call i32 @assert(i32 0)
br label %26
26: ; preds = %24, %22, %20, %18
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %14
29: ; preds = %26, %7
%30 = call i32 @putchar(i32 10)
%31 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %7
33: ; preds = %29, %1
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}