#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int flag, r;
  char buf[10];
  if ((argc > 1) && (strcmp(argv[1], "true") == 0)) {
    flag = fcntl(0, F_GETFL, 0);
    if (flag < 0) {
      perror("Fcntl F_GETFL");
      exit(EXIT_FAILURE);
    }
    flag = fcntl(0, F_SETFL, O_NONBLOCK);
    if (flag < 0) {
      perror("Fcntl F_SETFL");
      exit(EXIT_FAILURE);
    }
  }
  for (;;) {
    r = read(0, buf, 10);
    if ((r > 0) && (strncmp(buf, "quit", 4) == 0)) {
      exit(EXIT_SUCCESS);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    121c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121c <main+0xbc>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1040 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d7 <main+0x77>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1040 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1217 <main+0xb7>
lea    0xe0f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    121c <main+0xbc>
jmp    1221 <main+0xc1>
lea    -0x22(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    126b <main+0x10b>
lea    -0x22(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    126b <main+0x10b>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1221 <main+0xc1>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    11e0 <main+0x80>
mov    0x8(%rsi),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e0 <main+0x80>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
jns    119d <main+0x3d>
lea    0xe6a(%rip),%rdi
jmp    11c1 <main+0x61>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1040 <fcntl@plt>
test   %eax,%eax
jns    11e0 <main+0x80>
lea    0xe52(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe(%rsp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11e0 <main+0x80>
lea    0xe25(%rip),%rsi
lea    0xe(%rsp),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11e0 <main+0x80>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"true\00"
@F_GETFL = global i32 0
@.str.1 = [14 x i8] c"Fcntl F_GETFL\00"
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [14 x i8] c"Fcntl F_SETFL\00"
@.str.3 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %37
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %11
%18 = load i32, i32* @F_GETFL
%19 = call i32 @fcntl(i32 0, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = load i32, i32* @F_SETFL
%28 = load i32, i32* @O_NONBLOCK
%29 = call i32 @fcntl(i32 0, i32 %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
br label %37
37: ; preds = %36, %11, %2
br label %38
38: ; preds = %50, %37
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%40 = call i32 @read(i32 0, i8* %39, i32 10)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %38
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43, %38
br label %38
}

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@F_GETFL = global i32 0
@.str.1 = [14 x i8] c"Fcntl F_GETFL\00"
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [14 x i8] c"Fcntl F_SETFL\00"
@.str.3 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %7, label %6
6: ; preds = %20, %7, %2
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %7
%13 = load i32, i32* @F_GETFL
%14 = tail call i32 @fcntl(i32 0, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* @O_NONBLOCK
%23 = tail call i32 @fcntl(i32 0, i32 %21, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %6
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %35, %6
%30 = call i32 @read(i32 0, i8* %4, i32 10)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %32, %29
br label %29
36: ; preds = %32
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
}