#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 */
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int, char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int read_word(int max_len, char *target) {
  char new_char;
  int i;
  while ((new_char = fgetc(stdin) != ' ') && (new_char != '\n') &&
         (new_char != '\0') && (new_char == '\t'))
    ;
  for (i = 0; i < max_len - 1; i++) {
    new_char = (char)fgetc(stdin);
    fprintf(
        stderr,
        "DEBUG %s:%d: "
        "read_word: i = %d, new_char = '%c'."
        "\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/IO.h",
        42, i, new_char);
    target[i] = new_char;
    if ((new_char == ' ') || (new_char == '\n') || (new_char == '\0') ||
        (new_char == '\t')) {
      break;
    }
  }
  new_char = '\0';
  target[i] = new_char;
  fprintf(stderr,
          "DEBUG %s:%d: "
          "read_word: i = %d, new_char = '%c'"
          "\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/IO.h",
          53, i, new_char);
  return i;
}


x86 assembly (clang, -O0):
<read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
movsbl %al,%eax
cmp    $0x20,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1190 <read_word+0x70>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     1190 <read_word+0x70>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1190 <read_word+0x70>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <read_word+0x80>
jmp    11a5 <read_word+0x85>
jmp    112f <read_word+0xf>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1252 <read_word+0x132>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%r8d
lea    0xe1e(%rip),%rsi
lea    0xe49(%rip),%rdx
mov    $0x2a,%ecx
movsbl -0x11(%rbp),%r9d
call   1040 <fprintf@plt>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     123a <read_word+0x11a>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     123a <read_word+0x11a>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     123a <read_word+0x11a>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
jne    123f <read_word+0x11f>
jmp    1252 <read_word+0x132>
jmp    1244 <read_word+0x124>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <read_word+0x8c>
movb   $0x0,-0x11(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%r8d
lea    0xe3d(%rip),%rsi
lea    0xdb3(%rip),%rdx
mov    $0x35,%ecx
movsbl -0x11(%rbp),%r9d
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
xor    %ebx,%ebx
cmp    $0x2,%ebp
jl     11b7 <read_word+0x97>
add    $0xffffffff,%ebp
mov    %ebp,%r12d
xor    %ebx,%ebx
jmp    1159 <read_word+0x39>
nop
add    $0x1,%rbx
cmp    %rbx,%r12
je     11b5 <read_word+0x95>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,%r13d
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
movsbl %r13b,%r15d
lea    0xe82(%rip),%rsi
lea    0xead(%rip),%rdx
mov    $0x2a,%ecx
mov    %ebx,%r8d
mov    %r15d,%r9d
call   1040 <fprintf@plt>
mov    %r15b,(%r14,%rbx,1)
cmp    $0x20,%r13b
ja     1150 <read_word+0x30>
movzbl %r13b,%eax
movabs $0x100000601,%rcx
bt     %rax,%rcx
jae    1150 <read_word+0x30>
jmp    11b7 <read_word+0x97>
mov    %ebp,%ebx
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xee7(%rip),%rsi
lea    0xe5d(%rip),%rdx
mov    $0x35,%ecx
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"DEBUG %s:%d: read_word: i = %d, new_char = '%c'.\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/IO.h\00"
@.str.2 = [49 x i8] c"DEBUG %s:%d: read_word: i = %d, new_char = '%c'\0A\00"
define i32 @read_word(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
br label %7
7: ; preds = %30, %2
%8 = load i32, i32* @stdin
%9 = call signext i8 @fgetc(i32 %8)
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 32
%12 = zext i1 %11 to i32
%13 = trunc i32 %12 to i8
store i8 %13, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %7
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 9
br label %28
28: ; preds = %24, %20, %16, %7
%29 = phi i1 [ false, %20 ], [ false, %16 ], [ false, %7 ], [ %27, %24 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %7
31: ; preds = %28
store i32 0, i32* %6
br label %32
32: ; preds = %66, %31
%33 = load i32, i32* %6
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %69
37: ; preds = %32
%38 = load i32, i32* @stdin
%39 = call signext i8 @fgetc(i32 %38)
store i8 %39, i8* %5
%40 = load i32, i32* @stderr
%41 = load i32, i32* %6
%42 = load i8, i8* %5
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 42, i32 %41, i8 signext %42)
%44 = load i8, i8* %5
%45 = load i8*, i8** %4
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %64, label %52
52: ; preds = %37
%53 = load i8, i8* %5
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %64, label %56
56: ; preds = %52
%57 = load i8, i8* %5
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %56
%61 = load i8, i8* %5
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 9
br i1 %63, label %64, label %65
64: ; preds = %60, %56, %52, %37
br label %69
65: ; preds = %60
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %32
69: ; preds = %64, %32
store i8 0, i8* %5
%70 = load i8, i8* %5
%71 = load i8*, i8** %4
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 %70, i8* %74
%75 = load i32, i32* @stderr
%76 = load i32, i32* %6
%77 = load i8, i8* %5
%78 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %76, i8 signext %77)
%79 = load i32, i32* %6
ret i32 %79
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"DEBUG %s:%d: read_word: i = %d, new_char = '%c'.\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/IO.h\00"
@.str.2 = [49 x i8] c"DEBUG %s:%d: read_word: i = %d, new_char = '%c'\0A\00"
define i32 @read_word(i32 %0, i8* nocapture writeonly %1) {
%3 = load i32, i32* @stdin
%4 = tail call signext i8 @fgetc(i32 %3)
%5 = add i32 %0, -1
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %17
%10 = phi i64 [ 0, %7 ], [ %18, %17 ]
%11 = load i32, i32* @stdin
%12 = tail call signext i8 @fgetc(i32 %11)
%13 = load i32, i32* @stderr
%14 = trunc i64 %10 to i32
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 42, i32 %14, i8 signext %12)
%16 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %12, i8* %16
switch i8 %12, label %17 [
i8 32, label %20
i8 10, label %20
i8 9, label %20
i8 0, label %20
]
17: ; preds = %9
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %8
br i1 %19, label %22, label %9
20: ; preds = %9, %9, %9, %9
%21 = trunc i64 %10 to i32
br label %22
22: ; preds = %17, %20, %2
%23 = phi i32 [ 0, %2 ], [ %21, %20 ], [ %5, %17 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %23, i8 signext 0)
ret i32 %23
}