#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*/ printf(char *, ...);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int get_word(const char prompt[], char word[], size_t max) {
  char in[512];
  char holder[512];
  printf("%s ", prompt);
  while (fgets(in, 512, stdin) != NULL) {
    if (sscanf(in, "%s", holder) == 1) {
      if (strlen(holder) < max) {
        strcpy(word, holder);
        printf("%s", word);
        printf(" is the word you entered\n");
        return 1;
      }
      printf("not within bounds... try again: ");
    } else {
      printf("exiting\n\n");
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1244 <get_word+0xf4>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe52(%rip),%rsi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1225 <get_word+0xd5>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x20(%rbp),%rax
jae    1212 <get_word+0xc2>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <get_word+0xfb>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123f <get_word+0xef>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124b <get_word+0xfb>
jmp    1179 <get_word+0x29>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r13
mov    %rsi,0x8(%rsp)
mov    %rdi,%rsi
lea    0xe7d(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    0x210(%rsp),%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1256 <get_word+0xf6>
lea    0xe4d(%rip),%r12
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xe3c(%rip),%r15
xor    %ebp,%ebp
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1217 <get_word+0xb7>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %r13,%rax
jb     1222 <get_word+0xc2>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11d0 <get_word+0x70>
jmp    1256 <get_word+0xf6>
xor    %ebp,%ebp
lea    0xe08(%rip),%rdi
jmp    1251 <get_word+0xf1>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xdc9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebp
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [26 x i8] c" is the word you entered\0A\00"
@.str.3 = [33 x i8] c"not within bounds... try again: \00"
@.str.4 = [10 x i8] c"exiting\0A\0A\00"
define i32 @get_word(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %38, %3
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %13, i32 512, i32 %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %39
17: ; preds = %12
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = load i64, i64* %7
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %40
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %38
36: ; preds = %17
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %40
38: ; preds = %34
br label %12
39: ; preds = %12
store i32 0, i32* %4
br label %40
40: ; preds = %39, %36, %27
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [33 x i8] c"not within bounds... try again: \00"
@str = [9 x i8] c"exiting\0A\00"
@str.5 = [25 x i8] c" is the word you entered\00"
define i32 @get_word(i8* %0, i8* %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %6, i32 512, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %30, label %12
12: ; preds = %3, %21
%13 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = call i64 @strlen(i8* %7)
%17 = icmp ult i64 %16, %2
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @strcpy(i8* %1, i8* %7)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %26
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stdin
%24 = call i32* @fgets(i8* %6, i32 512, i32 %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %12
26: ; preds = %12, %18
%27 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0), %18 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0), %12 ]
%28 = phi i32 [ 1, %18 ], [ 0, %12 ]
%29 = call i32 @puts(i8* dereferenceable(1) %27)
br label %30
30: ; preds = %21, %26, %3
%31 = phi i32 [ 0, %3 ], [ %28, %26 ], [ 0, %21 ]
ret i32 %31
}