#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ readline(int, char *);
int /*<<< orphan*/ writeline(int, char *);
void check_and_return(int connfd) {
  char buffer[100];
  int fd;
  readline(connfd, buffer);
  if ((fd = open(buffer, O_RDONLY)) < 0) {
    writeline(connfd, "NO");
  }
  close(fd);
  writeline(connfd, "YES");
}


x86 assembly (clang, -O0):
<check_and_return>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1030 <readline@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    1187 <check_and_return+0x47>
mov    -0x4(%rbp),%edi
lea    0xe7e(%rip),%rsi
call   1060 <writeline@plt>
mov    -0x74(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
lea    0xe6a(%rip),%rsi
call   1060 <writeline@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_return>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebx
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1030 <readline@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1178 <check_and_return+0x38>
lea    0xe8f(%rip),%rsi
mov    %ebx,%edi
call   1060 <writeline@plt>
mov    %ebp,%edi
call   1040 <close@plt>
lea    0xe7d(%rip),%rsi
mov    %ebx,%edi
call   1060 <writeline@plt>
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"NO\00"
@.str.1 = [4 x i8] c"YES\00"
define void @check_and_return(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 @readline(i32 %5, i8* %6)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %2
%14 = call i32 @writeline(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %1
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %2
%19 = call i32 @writeline(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"NO\00"
@.str.1 = [4 x i8] c"YES\00"
define void @check_and_return(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @readline(i32 %0, i8* %3)
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* %3, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @writeline(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = call i32 @close(i32 %6)
%12 = call i32 @writeline(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
ret void
}