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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int write(int, char *, int);
void ps3_close(int ps3_ir) {
  int res;
  char buf[16];
  memset(buf, 0x0, sizeof(buf));
  buf[0] = 0x00;
  buf[1] = 0xAA;
  buf[2] = 0x00;
  buf[3] = 0x55;
  buf[4] = 0xA5;
  buf[5] = 0x5A;
  buf[6] = 0x66;
  buf[7] = 0x99;
  buf[8] = 0x69;
  res = write(ps3_ir, buf, 9);
  if (res < 0) {
    printf("Error: %d\n", errno);
    perror("write");
  } else {
    printf("write() wrote %d bytes\n", res);
  }
  close(ps3_ir);
  return;
}


x86 assembly (clang, -O0):
<ps3_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movb   $0x0,-0x20(%rbp)
movb   $0xaa,-0x1f(%rbp)
movb   $0x0,-0x1e(%rbp)
movb   $0x55,-0x1d(%rbp)
movb   $0xa5,-0x1c(%rbp)
movb   $0x5a,-0x1b(%rbp)
movb   $0x66,-0x1a(%rbp)
movb   $0x99,-0x19(%rbp)
movb   $0x69,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x9,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d3 <ps3_close+0x83>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
lea    0xe42(%rip),%rdi
call   1070 <perror@plt>
jmp    11e2 <ps3_close+0x92>
mov    -0x8(%rbp),%esi
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps3_close>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movabs $0x99665aa55500aa00,%rax
5a 66 99
mov    %rax,(%rsp)
movb   $0x69,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11ae <ps3_close+0x5e>
lea    0xe79(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
jmp    119f <ps3_close+0x4f>

LLVM IR (-O0):
@.str = [11 x i8] c"Error: %d\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [24 x i8] c"write() wrote %d bytes\0A\00"
define void @ps3_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 16)
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
store i8 0, i8* %7
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
store i8 -86, i8* %8
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
store i8 0, i8* %9
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
store i8 85, i8* %10
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
store i8 -91, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
store i8 90, i8* %12
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
store i8 102, i8* %13
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
store i8 -103, i8* %14
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
store i8 105, i8* %15
%16 = load i32, i32* %2
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 9)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %1
%22 = load i32, i32* @errno
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
25: ; preds = %1
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %2
%30 = call i32 @close(i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"Error: %d\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [24 x i8] c"write() wrote %d bytes\0A\00"
define void @ps3_close(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 16)
store i8 0, i8* %3
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 1
store i8 -86, i8* %5
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 2
store i8 0, i8* %6
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 3
store i8 85, i8* %7
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 4
store i8 -91, i8* %8
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 5
store i8 90, i8* %9
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 6
store i8 102, i8* %10
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 7
store i8 -103, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 8
store i8 105, i8* %12
%13 = call i32 @write(i32 %0, i8* %3, i32 9)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @errno
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %1
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %21
21: ; preds = %19, %15
%22 = call i32 @close(i32 %0)
ret void
}