#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int read_word_from_file(FILE *f, char *wrd) {
  long long char_idx = 0;
  if (!f || !wrd || feof(f))
    return -1;
  wrd[0] = 0;
  while (!feof(f)) {
    char word_char = 0;
    word_char = fgetc(f);
    if (word_char != '\n' && (int)word_char >= 0) {
      wrd[char_idx] = word_char;
      char_idx++;
      wrd[char_idx] = 0;
    } else
      break;
  }
  if (char_idx == 0)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<read_word_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1161 <read_word_from_file+0x41>
cmpq   $0x0,-0x18(%rbp)
je     1161 <read_word_from_file+0x41>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     116d <read_word_from_file+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <read_word_from_file+0xf0>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1193 <read_word_from_file+0x73>
jmp    11f2 <read_word_from_file+0xd2>
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
je     11e8 <read_word_from_file+0xc8>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jl     11e8 <read_word_from_file+0xc8>
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ed <read_word_from_file+0xcd>
jmp    11f2 <read_word_from_file+0xd2>
jmp    1174 <read_word_from_file+0x54>
cmpq   $0x0,-0x20(%rbp)
jne    1209 <read_word_from_file+0xe9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <read_word_from_file+0xf0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_word_from_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11ae <read_word_from_file+0x8e>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ae <read_word_from_file+0x8e>
mov    %rdi,%rbx
call   1040 <feof@plt>
test   %rax,%rax
jne    11ae <read_word_from_file+0x8e>
movb   $0x0,(%r14)
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %rax,%rax
je     1160 <read_word_from_file+0x40>
mov    $0xffffffff,%r15d
jmp    11ae <read_word_from_file+0x8e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     11a3 <read_word_from_file+0x83>
test   %al,%al
js     11a3 <read_word_from_file+0x83>
mov    %al,(%r14,%rbp,1)
movb   $0x0,0x1(%r14,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %rax,%rax
je     1170 <read_word_from_file+0x50>
mov    $0x1,%r15d
jmp    11ae <read_word_from_file+0x8e>
mov    $0x1,%r15d
test   %rbp,%rbp
je     1158 <read_word_from_file+0x38>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_word_from_file(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 0, i64* %6
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = call i64 @feof(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %10, %2
store i32 -1, i32* %3
br label %53
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
br label %21
21: ; preds = %47, %18
%22 = load i32*, i32** %4
%23 = call i64 @feof(i32* %22)
%24 = icmp ne i64 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %48
26: ; preds = %21
store i8 0, i8* %7
%27 = load i32*, i32** %4
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %7
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %46
32: ; preds = %26
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i8, i8* %7
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
%41 = load i64, i64* %6
%42 = add nsw i64 %41, 1
store i64 %42, i64* %6
%43 = load i8*, i8** %5
%44 = load i64, i64* %6
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8 0, i8* %45
br label %47
46: ; preds = %32, %26
br label %48
47: ; preds = %36
br label %21
48: ; preds = %46, %21
%49 = load i64, i64* %6
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 -1, i32* %3
br label %53
52: ; preds = %48
store i32 1, i32* %3
br label %53
53: ; preds = %52, %51, %17
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
define i32 @read_word_from_file(i32* %0, i8* writeonly %1) {
%3 = icmp ne i32* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = tail call i64 @feof(i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %6
store i8 0, i8* %1
%10 = tail call i64 @feof(i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %9, %18
%13 = phi i64 [ %20, %18 ], [ 0, %9 ]
%14 = tail call signext i8 @fgetc(i32* %0)
%15 = icmp ne i8 %14, 10
%16 = icmp sgt i8 %14, -1
%17 = and i1 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %14, i8* %19
%20 = add nuw nsw i64 %13, 1
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
%22 = tail call i64 @feof(i32* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %12, label %27
24: ; preds = %12
%25 = icmp eq i64 %13, 0
br i1 %25, label %26, label %27
26: ; preds = %9, %24
br label %27
27: ; preds = %18, %26, %24, %2, %6
%28 = phi i32 [ -1, %6 ], [ -1, %2 ], [ -1, %26 ], [ 1, %24 ], [ 1, %18 ]
ret i32 %28
}