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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
char atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  char n;
  int devfd;
  ssize_t nr;
  if (argc < 2) {
    fprintf(stderr, "usage: %s <int1> [<int2> ...]\n", argv[0]);
    return EXIT_FAILURE;
  }
  devfd = open("/dev/fifo0", O_WRONLY);
  if (-1 == n) {
    perror("open()");
    return EXIT_FAILURE;
  }
  for (i = 1; i < argc; i++) {
    n = atoi(argv[i]);
    nr = write(devfd, &n, sizeof(n));
    if (-1 == nr) {
      perror("write()");
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


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)
jge    119d <main+0x4d>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1268 <main+0x118>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e3 <main+0x93>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1268 <main+0x118>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125c <main+0x10c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %al,-0x15(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    1249 <main+0xf9>
lea    0xdfe(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1268 <main+0x118>
jmp    124e <main+0xfe>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <main+0x9a>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x1,%edi
jg     1185 <main+0x35>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e55(%rip),%r15
jmp    11eb <main+0x9b>
mov    %edi,%r14d
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r13d
mov    %r14d,%ebx
mov    $0x1,%ebp
lea    0x7(%rsp),%r14
mov    0x2e1c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbp,8),%rdi
call   1070 <atoi@plt>
mov    %al,0x7(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11fd <main+0xad>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <main+0x70>
mov    (%r15),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
jmp    117c <main+0x2c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s <int1> [<int2> ...]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"/dev/fifo0\00"
@O_WRONLY = global i32 0
@.str.2 = [7 x i8] c"open()\00"
@.str.3 = [8 x i8] c"write()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %53
19: ; preds = %2
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 %21, i32* %8
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %53
28: ; preds = %19
store i32 1, i32* %6
br label %29
29: ; preds = %48, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %51
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call signext i8 @atoi(i8* %38)
store i8 %39, i8* %7
%40 = load i32, i32* %8
%41 = call i32 @write(i32 %40, i8* %7, i32 1)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp eq i32 -1, %42
br i1 %43, label %44, label %47
44: ; preds = %33
%45 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %53
47: ; preds = %33
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %29
51: ; preds = %29
%52 = load i32, i32* @EXIT_SUCCESS
store i32 %52, i32* %3
br label %53
53: ; preds = %51, %44, %25, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s <int1> [<int2> ...]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"/dev/fifo0\00"
@O_WRONLY = global i32 0
@.str.3 = [8 x i8] c"write()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %25
9: ; preds = %2
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = zext i32 %0 to i64
br label %15
13: ; preds = %15
%14 = icmp eq i64 %22, %12
br i1 %14, label %25, label %15
15: ; preds = %9, %13
%16 = phi i64 [ 1, %9 ], [ %22, %13 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call signext i8 @atoi(i8* %18)
store i8 %19, i8* %3
%20 = call i32 @write(i32 %11, i8* %3, i32 1)
%21 = icmp eq i32 %20, -1
%22 = add nuw nsw i64 %16, 1
br i1 %21, label %23, label %13
23: ; preds = %15
%24 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %13, %23, %5
%26 = phi i32* [ @EXIT_FAILURE, %5 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_SUCCESS, %13 ]
%27 = load i32, i32* %26
ret i32 %27
}