#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ S_IRWXU;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ create_dirtree(char const *);
int /*<<< orphan*/ err(char *, char const *);
int mkfifo(char *, int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
int stat(char *, struct stat *);
int open_channel(const char *channel) {
  struct stat st;
  char infile[256] = "in";
  if (*channel) {
    if (!create_dirtree(channel))
      err("cannot create channel directory '%s'\n", channel);
    snprintf(infile, sizeof infile, "%s/%s", channel, "in");
  }
  if (stat(infile, &st) == -1 && mkfifo(infile, S_IRWXU) == -1)
    err("cannot create channel fifo '%s'\n", infile);
  else if (access(infile, F_OK) == -1)
    err("cannot access channel fifo '%s'\n", infile);
  return open(infile, O_RDONLY | O_NONBLOCK, 0);
}


x86 assembly (clang, -O0):
<open_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movb   $0x69,-0x110(%rbp)
movb   $0x6e,-0x10f(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1202 <open_channel+0x82>
mov    -0x8(%rbp),%rdi
call   10a0 <create_dirtree@plt>
cmp    $0x0,%eax
jne    11df <open_channel+0x5f>
mov    -0x8(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1070 <err@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe30(%rip),%rdx
lea    0xe2f(%rip),%r8
call   1030 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1251 <open_channel+0xd1>
lea    -0x110(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1050 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    1251 <open_channel+0xd1>
lea    -0x110(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1070 <err@plt>
jmp    1287 <open_channel+0x107>
lea    -0x110(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    1282 <open_channel+0x102>
lea    -0x110(%rbp),%rsi
lea    0xdd3(%rip),%rdi
call   1070 <err@plt>
jmp    1287 <open_channel+0x107>
lea    -0x110(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d42(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_channel>:
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movw   $0x6e69,0x10(%rsp)
cmpb   $0x0,(%rdi)
je     122d <open_channel+0xbd>
mov    %rdi,%rbx
call   1090 <create_dirtree@plt>
test   %eax,%eax
jne    120d <open_channel+0x9d>
lea    0xdfb(%rip),%rdi
mov    %rbx,%rsi
call   1060 <err@plt>
lea    0xe12(%rip),%rdx
lea    0xe11(%rip),%r8
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    1259 <open_channel+0xe9>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1040 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     127a <open_channel+0x10a>
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    128b <open_channel+0x11b>
lea    0xdd8(%rip),%rdi
jmp    1281 <open_channel+0x111>
lea    0xdae(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <err@plt>
mov    0x2d46(%rip),%rax
mov    0x2d47(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x10(%rsp),%rdi
xor    %edx,%edx
call   1070 <open@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [38 x i8] c"cannot create channel directory '%s'\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [3 x i8] c"in\00"
@S_IRWXU = global i32 0
@.str.3 = [33 x i8] c"cannot create channel fifo '%s'\0A\00"
@F_OK = global i32 0
@.str.4 = [33 x i8] c"cannot access channel fifo '%s'\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @open_channel(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca [256 x i8]
store i8* %0, i8** %2
%5 = bitcast [256 x i8]* %4 to i8*
%6 = bitcast i8* %5 to [256 x i8]*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 0
store i8 105, i8* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 1
store i8 110, i8* %8
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @create_dirtree(i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i32 @err(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %12
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 @snprintf(i8* %20, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %19, %1
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = call i32 @stat(i8* %24, %struct.stat* %3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%29 = load i32, i32* @S_IRWXU
%30 = call i32 @mkfifo(i8* %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = call i32 @err(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %44
35: ; preds = %27, %23
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = load i32, i32* @F_OK
%38 = call i32 @access(i8* %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%42 = call i32 @err(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %35
br label %44
44: ; preds = %43, %32
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%46 = load i32, i32* @O_RDONLY
%47 = load i32, i32* @O_NONBLOCK
%48 = or i32 %46, %47
%49 = call i32 @open(i8* %45, i32 %48, i32 0)
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [38 x i8] c"cannot create channel directory '%s'\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [3 x i8] c"in\00"
@S_IRWXU = global i32 0
@.str.3 = [33 x i8] c"cannot create channel fifo '%s'\0A\00"
@F_OK = global i32 0
@.str.4 = [33 x i8] c"cannot access channel fifo '%s'\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @open_channel(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca [256 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8 105, i8* %5
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
store i8 110, i8* %6
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = tail call i32 @create_dirtree(i8* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @err(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %9
%15 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = call i32 @stat(i8* %5, %struct.stat* %2)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @S_IRWXU
%21 = call i32 @mkfifo(i8* %5, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %27, label %23
23: ; preds = %19, %16
%24 = load i32, i32* @F_OK
%25 = call i32 @access(i8* %5, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23, %19
%28 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), %19 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %23 ]
%29 = call i32 @err(i8* %28, i8* %5)
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* @O_RDONLY
%32 = load i32, i32* @O_NONBLOCK
%33 = or i32 %32, %31
%34 = call i32 @open(i8* %5, i32 %33, i32 0)
ret i32 %34
}