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

/* Variables and functions */
char atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  char *device = "/dev/psaux";
  FILE *f;
  char buf[2] = {0xF3, 100};
  if (!(f = fopen(device, "w"))) {
    perror(device);
    exit(1);
  }
  if (argc > 1)
    buf[1] = atoi(argv[1]);
  fwrite(buf, 1, 2, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe85(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11bd <main+0x5d>
mov    -0x18(%rbp),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11d7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %al,-0x21(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movw   $0x64f3,0xe(%rsp)
lea    0xe85(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11cb <main+0x6b>
mov    %rax,%rbx
cmp    $0x2,%ebp
jl     11a1 <main+0x41>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %al,0xf(%rsp)
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/psaux\00"
@__const.main.buf = [2 x i8] c"\F3d"
@.str.1 = [2 x i8] c"w\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 [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = bitcast [2 x i8]* %8 to i8*
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call signext i8 @atoi(i8* %23)
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %24, i8* %25
br label %26
26: ; preds = %20, %17
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %7
%29 = call i32 @fwrite(i8* %27, i32 1, i32 2, i32* %28)
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/psaux\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to [2 x i8]*
%5 = bitcast i16* %3 to i8*
store i16 25843, i16* %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call signext i8 @atoi(i8* %15)
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 %16, i8* %17
br label %18
18: ; preds = %13, %11
%19 = call i32 @fwrite(i8* %5, i32 1, i32 2, i32* %6)
%20 = tail call i32 @fclose(i32* %6)
ret i32 0
}