#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 */
scalar_t__ EBADF;
int /*<<< orphan*/ F_GETFL;
int atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  if (argc != 2) {
    fprintf(stderr, "Only two arguments: %s <fd>\n", argv[0]);
    exit(1);
  }
  fd = atoi(argv[1]);
  if (fcntl(fd, F_GETFL) < 0 && errno == EBADF)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1186 <main+0x46>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11d7 <main+0x97>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%rax
jne    11d7 <main+0x97>
movl   $0x0,-0x4(%rbp)
jmp    11de <main+0x9e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    1183 <main+0x43>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
jns    117c <main+0x3c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rcx
mov    0x2e53(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1181 <main+0x41>
mov    $0x1,%eax
pop    %rcx
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe6a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Only two arguments: %s <fd>\0A\00"
@F_GETFL = global i32 0
@errno = global i64 0
@EBADF = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = load i32, i32* @F_GETFL
%23 = call i64 @fcntl(i32 %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load i64, i64* @errno
%27 = load i64, i64* @EBADF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %3
br label %31
30: ; preds = %25, %16
store i32 1, i32* %3
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Only two arguments: %s <fd>\0A\00"
@F_GETFL = global i32 0
@errno = global i64 0
@EBADF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = load i32, i32* @F_GETFL
%14 = tail call i64 @fcntl(i32 %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i64, i64* @errno
%18 = load i64, i64* @EBADF
%19 = icmp eq i64 %17, %18
br i1 %19, label %21, label %20
20: ; preds = %16, %9
br label %21
21: ; preds = %16, %20
%22 = phi i32 [ 1, %20 ], [ 0, %16 ]
ret i32 %22
}