#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int main(void) {
  char buf[64];
  int fd;
  fd = open("/proc/self/wchan", O_RDONLY);
  if (fd == -1) {
    if (errno == ENOENT)
      return 2;
    return 1;
  }
  buf[0] = '\0';
  if (read(fd, buf, sizeof(buf)) != 1)
    return 1;
  if (buf[0] != '0')
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
lea    0xec1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1183 <main+0x63>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    1177 <main+0x57>
movl   $0x2,-0x4(%rbp)
jmp    11cd <main+0xad>
movl   $0x1,-0x4(%rbp)
jmp    11cd <main+0xad>
movb   $0x0,-0x50(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     11ad <main+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    11cd <main+0xad>
movsbl -0x50(%rbp),%eax
cmp    $0x30,%eax
je     11c6 <main+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11cd <main+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
mov    0x2ebd(%rip),%rax
mov    (%rax),%esi
lea    0xecc(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     116b <main+0x4b>
movb   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x40,%edx
call   1030 <read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
jne    1166 <main+0x46>
xor    %eax,%eax
cmpb   $0x30,(%rsp)
setne  %al
add    $0x48,%rsp
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%rcx
mov    0x2e4c(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
sete   %al
add    $0x1,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/self/wchan\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 2, i32* %1
br label %28
13: ; preds = %8
store i32 1, i32* %1
br label %28
14: ; preds = %0
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
store i8 0, i8* %15
%16 = load i32, i32* %3
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 64)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 1, i32* %1
br label %28
21: ; preds = %14
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 48
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 1, i32* %1
br label %28
27: ; preds = %21
store i32 0, i32* %1
br label %28
28: ; preds = %27, %26, %20, %13, %12
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/self/wchan\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
%10 = select i1 %9, i32 2, i32 1
br label %18
11: ; preds = %0
store i8 0, i8* %2
%12 = call i32 @read(i32 %4, i8* %2, i32 64)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8, i8* %2
%16 = icmp ne i8 %15, 48
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %14, %11, %6
%19 = phi i32 [ %10, %6 ], [ 1, %11 ], [ %17, %14 ]
ret i32 %19
}