#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*/ which;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
char atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char which;
  int ret;
  int fd;
  if (argc != 2) {
    printf("usage: %s 0|1\n", argv[0]);
    exit(1);
  }
  which = atoi(argv[1]);
  fd = open("/dev/devns.fifo", O_WRONLY);
  if (fd < 0) {
    printf("Failed to open fifo: %s\n", strerror(errno));
    exit(1);
  }
  ret = write(fd, &which, sizeof(which));
  if (ret != (int)sizeof(which))
    printf("Failed to write to fifo: %s\n", strerror(errno));
  close(fd);
  return 0;
}


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     11ad <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %al,-0x11(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1206 <main+0x96>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1241 <main+0xd1>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11e4 <main+0x74>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %al,0xf(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11f0 <main+0x80>
mov    %eax,%ebx
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11d5 <main+0x65>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe6b(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe12(%rip),%rdi
jmp    1208 <main+0x98>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe1a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"usage: %s 0|1\0A\00"
@.str.1 = [16 x i8] c"/dev/devns.fifo\00"
@O_WRONLY = global i32 0
@.str.2 = [25 x i8] c"Failed to open fifo: %s\0A\00"
@errno = global i32 0
@.str.3 = [29 x i8] c"Failed to write to fifo: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call signext i8 @atoi(i8* %20)
store i8 %21, i8* %6
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i32, i32* %8
%33 = call i32 @write(i32 %32, i8* %6, i32 1)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %31
%41 = load i32, i32* %8
%42 = call i32 @close(i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"usage: %s 0|1\0A\00"
@.str.1 = [16 x i8] c"/dev/devns.fifo\00"
@O_WRONLY = global i32 0
@.str.2 = [25 x i8] c"Failed to open fifo: %s\0A\00"
@errno = global i32 0
@.str.3 = [29 x i8] c"Failed to write to fifo: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 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 signext i8 @atoi(i8* %11)
store i8 %12, i8* %3
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = call i32 @write(i32 %14, i8* %3, i32 1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %24, %21
%29 = tail call i32 @close(i32 %14)
ret i32 0
}