#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int ams_getflag(char *flag) {
  int i = 0;
  (void)memset(flag, 0, (8));
  for (flag[0] = 'Y'; i < (3); i++) {
    if (fgets(flag, (8) - (1), stdin) == NULL) {
      printf("Manage: flag too long, try again.\n");
      (void)memset(flag, 0, (8));
      continue;
    }
    flag[1] = '\0';
    if ((flag[0] != 'Y') && (flag[0] != 'y') && (flag[0] != 'N') &&
        (flag[0] != 'n')) {
      printf("Manage: invalid flag, try again.\n");
      (void)memset(flag, 0, (8));
    } else
      break;
  }
  if (i >= (3)) {
    printf("Manage: 3 times failure, exit\n");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<ams_getflag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
movb   $0x59,(%rax)
cmpl   $0x3,-0x14(%rbp)
jge    1227 <ams_getflag+0xf7>
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11a6 <ams_getflag+0x76>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
jmp    1219 <ams_getflag+0xe9>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x59,%eax
je     120f <ams_getflag+0xdf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x79,%eax
je     120f <ams_getflag+0xdf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4e,%eax
je     120f <ams_getflag+0xdf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6e,%eax
je     120f <ams_getflag+0xdf>
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
jmp    1214 <ams_getflag+0xe4>
jmp    1227 <ams_getflag+0xf7>
jmp    1219 <ams_getflag+0xe9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <ams_getflag+0x2a>
cmpl   $0x3,-0x14(%rbp)
jl     1249 <ams_getflag+0x119>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <ams_getflag+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ams_getflag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movb   $0x59,(%rbx)
mov    0x2e96(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <fgets@plt>
lea    0xed6(%rip),%r14
mov    %r14,%rdi
test   %rax,%rax
je     119b <ams_getflag+0x6b>
movb   $0x0,0x1(%rbx)
mov    (%rbx),%al
lea    0xea0(%rip),%rdi
add    $0xb2,%al
cmp    $0x2b,%al
ja     119b <ams_getflag+0x6b>
movzbl %al,%eax
movabs $0x80100000801,%rcx
bt     %rax,%rcx
jb     1268 <ams_getflag+0x138>
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
test   %rax,%rax
je     11ef <ams_getflag+0xbf>
movb   $0x0,0x1(%rbx)
mov    (%rbx),%al
lea    0xe48(%rip),%rdi
add    $0xb2,%al
cmp    $0x2b,%al
ja     11ef <ams_getflag+0xbf>
movzbl %al,%eax
movabs $0x80100000801,%rcx
bt     %rax,%rcx
jb     1268 <ams_getflag+0x138>
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1240 <ams_getflag+0x110>
movb   $0x0,0x1(%rbx)
mov    (%rbx),%al
lea    0xdf7(%rip),%r14
add    $0xb2,%al
cmp    $0x2b,%al
ja     1240 <ams_getflag+0x110>
movzbl %al,%eax
movabs $0x80100000801,%rcx
bt     %rax,%rcx
jb     1268 <ams_getflag+0x138>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [35 x i8] c"Manage: flag too long, try again.\0A\00"
@.str.1 = [34 x i8] c"Manage: invalid flag, try again.\0A\00"
@.str.2 = [31 x i8] c"Manage: 3 times failure, exit\0A\00"
define i32 @ams_getflag(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = call i32 @memset(i8* %5, i32 0, i32 8)
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 89, i8* %8
br label %9
9: ; preds = %53, %1
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %56
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %13, i32 7, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = call i32 @memset(i8* %19, i32 0, i32 8)
br label %53
21: ; preds = %12
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 89
br i1 %28, label %29, label %51
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 121
br i1 %34, label %35, label %51
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 78
br i1 %40, label %41, label %51
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 110
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%49 = load i8*, i8** %3
%50 = call i32 @memset(i8* %49, i32 0, i32 8)
br label %52
51: ; preds = %41, %35, %29, %21
br label %56
52: ; preds = %47
br label %53
53: ; preds = %52, %17
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %9
56: ; preds = %51, %9
%57 = load i32, i32* %4
%58 = icmp sge i32 %57, 3
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %62
61: ; preds = %56
store i32 0, i32* %2
br label %62
62: ; preds = %61, %59
%63 = load i32, i32* %2
ret i32 %63
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [30 x i8] c"Manage: 3 times failure, exit\00"
@str.3 = [33 x i8] c"Manage: invalid flag, try again.\00"
@str.4 = [34 x i8] c"Manage: flag too long, try again.\00"
define i32 @ams_getflag(i8* %0) {
%2 = tail call i32 @memset(i8* %0, i32 0, i32 8)
store i8 89, i8* %0
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i32, i32* @stdin
%5 = tail call i32* @fgets(i8* %0, i32 7, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
store i8 0, i8* %3
%8 = load i8, i8* %0
switch i8 %8, label %9 [
i8 89, label %32
i8 121, label %32
i8 78, label %32
i8 110, label %32
]
9: ; preds = %7, %1
%10 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.3, i64 0, i64 0), %7 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call i32 @memset(i8* %0, i32 0, i32 8)
%13 = load i32, i32* @stdin
%14 = tail call i32* @fgets(i8* %0, i32 7, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %9
store i8 0, i8* %3
%17 = load i8, i8* %0
switch i8 %17, label %18 [
i8 89, label %32
i8 121, label %32
i8 78, label %32
i8 110, label %32
]
18: ; preds = %9, %16
%19 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.3, i64 0, i64 0), %16 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0), %9 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
%21 = tail call i32 @memset(i8* %0, i32 0, i32 8)
%22 = load i32, i32* @stdin
%23 = tail call i32* @fgets(i8* %0, i32 7, i32 %22)
%24 = icmp eq i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %18
store i8 0, i8* %3
%26 = load i8, i8* %0
switch i8 %26, label %27 [
i8 89, label %32
i8 121, label %32
i8 78, label %32
i8 110, label %32
]
27: ; preds = %18, %25
%28 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.3, i64 0, i64 0), %25 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0), %18 ]
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
%30 = tail call i32 @memset(i8* %0, i32 0, i32 8)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %7, %7, %7, %7, %16, %16, %16, %16, %25, %25, %25, %25, %27
%33 = phi i32 [ -1, %27 ], [ 0, %25 ], [ 0, %25 ], [ 0, %25 ], [ 0, %25 ], [ 0, %16 ], [ 0, %16 ], [ 0, %16 ], [ 0, %16 ], [ 0, %7 ], [ 0, %7 ], [ 0, %7 ], [ 0, %7 ]
ret i32 %33
}