#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
void read_tok(char *fname) {
  char buffer[100];
  FILE *fp = fopen(fname, "r");
  while (fgets(buffer, sizeof(buffer), fp)) {
    if (strlen(buffer) != 1) {
      char *pch = strtok(buffer, " !,.?\n");
      while (pch != NULL) {
        printf("%s\n", pch);
        pch = strtok(NULL, " !,.?\n");
      }
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_tok>:
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,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1203 <read_tok+0xa3>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11fe <read_tok+0x9e>
lea    -0x70(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     11f9 <read_tok+0x99>
mov    -0x80(%rbp),%rsi
lea    0xe2e(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe17(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x80(%rbp)
jmp    11c5 <read_tok+0x65>
jmp    11fe <read_tok+0x9e>
jmp    1183 <read_tok+0x23>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_tok>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fc <read_tok+0x9c>
mov    %rsp,%r15
lea    0xe69(%rip),%rbx
lea    0xe69(%rip),%r12
jmp    11c5 <read_tok+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fc <read_tok+0x9c>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
je     11b0 <read_tok+0x50>
mov    %r15,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11b0 <read_tok+0x50>
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
jmp    11e0 <read_tok+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c" !,.?\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @read_tok(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
br label %8
8: ; preds = %28, %1
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %4
%11 = call i64 @fgets(i8* %9, i32 100, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %5
br label %20
20: ; preds = %23, %17
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %5
br label %20
27: ; preds = %20
br label %28
28: ; preds = %27, %13
br label %8
29: ; preds = %8
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c" !,.?\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @read_tok(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %1, %18
%8 = call i32 @strlen(i8* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10, %13
%14 = phi i8* [ %16, %13 ], [ %11, %10 ]
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %13
18: ; preds = %13, %10, %7
%19 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %18, %1
%22 = call i32 @fclose(i32* %4)
ret void
}