#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 */
int /*<<< orphan*/ AO_add_channel(int, int, int, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int write(int, short *, int);
int main(int argc, char *argv[]) {
  int ao;
  signed short buf[2];
  int u;
  ao = open("/dev/niao0", O_WRONLY);
  if (ao == -1) {
    perror("can't open niao0");
    return 0;
  }
  int r = 0;
  if (argc < 2) {
    AO_add_channel(ao, 0, 1, 0, 0, 0);
    AO_add_channel(ao, 1, 1, 0, 0, 0);
    buf[0] = 0;
    buf[1] = 0;
    r = write(ao, buf, 4);
  } else if (argc == 2) {
    AO_add_channel(ao, 0, 1, 0, 0, 0);
    sscanf(argv[1], "%d", &u);
    buf[0] = u;
    r = write(ao, buf, 2);
  } else {
    AO_add_channel(ao, 0, 1, 0, 0, 0);
    AO_add_channel(ao, 1, 1, 0, 0, 0);
    sscanf(argv[1], "%d", &u);
    buf[0] = u;
    sscanf(argv[2], "%d", &u);
    buf[1] = u;
    r = write(ao, buf, 4);
  }
  if (r < 0)
    perror("write failed");
  close(ao);
  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)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b0 <main+0x50>
lea    0xe6c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    131f <main+0x1bf>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1217 <main+0xb7>
mov    -0x14(%rbp),%edi
xor    %r9d,%r9d
mov    $0x1,%edx
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <AO_add_channel@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
xor    %r9d,%r9d
mov    %edx,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <AO_add_channel@plt>
movw   $0x0,-0x18(%rbp)
movw   $0x0,-0x16(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
jmp    12fa <main+0x19a>
cmpl   $0x2,-0x8(%rbp)
jne    1272 <main+0x112>
mov    -0x14(%rbp),%edi
xor    %r9d,%r9d
mov    $0x1,%edx
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <AO_add_channel@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd3(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %ax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
jmp    12f5 <main+0x195>
mov    -0x14(%rbp),%edi
xor    %r9d,%r9d
mov    $0x1,%edx
mov    %r9d,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <AO_add_channel@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
xor    %r9d,%r9d
mov    %edx,%esi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <AO_add_channel@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6a(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %ax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd4b(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %ax,-0x16(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
jmp    12fa <main+0x19a>
cmpl   $0x0,-0x20(%rbp)
jge    1310 <main+0x1b0>
lea    0xd14(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     127d <main+0x11d>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
cmp    $0x1,%ebp
jg     11cc <main+0x6c>
call   1040 <AO_add_channel@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <AO_add_channel@plt>
movl   $0x0,(%rsp)
jmp    1256 <main+0xf6>
call   1040 <AO_add_channel@plt>
cmp    $0x2,%ebp
jne    1200 <main+0xa0>
mov    0x8(%r14),%rdi
lea    0xe3b(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1060 <sscanf@plt>
movzwl 0x4(%rsp),%eax
mov    %ax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x2,%edx
jmp    1260 <main+0x100>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <AO_add_channel@plt>
mov    0x8(%r14),%rdi
lea    0xdf8(%rip),%rbp
lea    0x4(%rsp),%r15
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
movzwl 0x4(%rsp),%eax
mov    %ax,(%rsp)
mov    0x10(%r14),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
movzwl 0x4(%rsp),%eax
mov    %ax,0x2(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     128b <main+0x12b>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd87(%rip),%rdi
call   1080 <perror@plt>
jmp    1270 <main+0x110>
lea    0xd8d(%rip),%rdi
call   1080 <perror@plt>
jmp    1269 <main+0x109>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/niao0\00"
@O_WRONLY = global i32 0
@.str.1 = [17 x i8] c"can't open niao0\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"write failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i16]
%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* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %76
16: ; preds = %2
store i32 0, i32* %9
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i32, i32* %6
%21 = call i32 @AO_add_channel(i32 %20, i32 0, i32 1, i32 0, i32 0, i32 0)
%22 = load i32, i32* %6
%23 = call i32 @AO_add_channel(i32 %22, i32 1, i32 1, i32 0, i32 0, i32 0)
%24 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
store i16 0, i16* %24
%25 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 1
store i16 0, i16* %25
%26 = load i32, i32* %6
%27 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
%28 = call i32 @write(i32 %26, i16* %27, i32 4)
store i32 %28, i32* %9
br label %68
29: ; preds = %16
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i32, i32* %6
%34 = call i32 @AO_add_channel(i32 %33, i32 0, i32 1, i32 0, i32 0, i32 0)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%39 = load i32, i32* %8
%40 = trunc i32 %39 to i16
%41 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
store i16 %40, i16* %41
%42 = load i32, i32* %6
%43 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
%44 = call i32 @write(i32 %42, i16* %43, i32 2)
store i32 %44, i32* %9
br label %67
45: ; preds = %29
%46 = load i32, i32* %6
%47 = call i32 @AO_add_channel(i32 %46, i32 0, i32 1, i32 0, i32 0, i32 0)
%48 = load i32, i32* %6
%49 = call i32 @AO_add_channel(i32 %48, i32 1, i32 1, i32 0, i32 0, i32 0)
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%54 = load i32, i32* %8
%55 = trunc i32 %54 to i16
%56 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
store i16 %55, i16* %56
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 @sscanf(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%61 = load i32, i32* %8
%62 = trunc i32 %61 to i16
%63 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 1
store i16 %62, i16* %63
%64 = load i32, i32* %6
%65 = getelementptr inbounds [2 x i16], [2 x i16]* %7, i64 0, i64 0
%66 = call i32 @write(i32 %64, i16* %65, i32 4)
store i32 %66, i32* %9
br label %67
67: ; preds = %45, %32
br label %68
68: ; preds = %67, %19
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
%74 = load i32, i32* %6
%75 = call i32 @close(i32 %74)
store i32 0, i32* %3
br label %76
76: ; preds = %73, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/niao0\00"
@O_WRONLY = global i32 0
@.str.1 = [17 x i8] c"can't open niao0\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"write failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i16]
%4 = alloca i32
%5 = bitcast [2 x i16]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %53
12: ; preds = %2
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = tail call i32 @AO_add_channel(i32 %8, i32 0, i32 1, i32 0, i32 0, i32 0)
%16 = tail call i32 @AO_add_channel(i32 %8, i32 1, i32 1, i32 0, i32 0, i32 0)
%17 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
store i16 0, i16* %17
%18 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 1
store i16 0, i16* %18
%19 = call i32 @write(i32 %8, i16* %17, i32 4)
br label %46
20: ; preds = %12
%21 = icmp eq i32 %0, 2
%22 = tail call i32 @AO_add_channel(i32 %8, i32 0, i32 1, i32 0, i32 0, i32 0)
br i1 %21, label %23, label %31
23: ; preds = %20
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%27 = load i32, i32* %4
%28 = trunc i32 %27 to i16
%29 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
store i16 %28, i16* %29
%30 = call i32 @write(i32 %8, i16* %29, i32 2)
br label %46
31: ; preds = %20
%32 = tail call i32 @AO_add_channel(i32 %8, i32 1, i32 1, i32 0, i32 0, i32 0)
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%36 = load i32, i32* %4
%37 = trunc i32 %36 to i16
%38 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
store i16 %37, i16* %38
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%42 = load i32, i32* %4
%43 = trunc i32 %42 to i16
%44 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 1
store i16 %43, i16* %44
%45 = call i32 @write(i32 %8, i16* %38, i32 4)
br label %46
46: ; preds = %23, %31, %14
%47 = phi i32 [ %19, %14 ], [ %30, %23 ], [ %45, %31 ]
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = call i32 @close(i32 %8)
br label %53
53: ; preds = %51, %10
ret i32 0
}