#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 errno;
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int write(int, char *, int);
void ps3_set_mode(int ps3_ir, char mode) {
  int i, 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);
  }
  buf[0] = 0x00;
  buf[1] = 0x00;
  buf[2] = 0xA6;
  buf[3] = 0x00;
  buf[4] = 0x00;
  buf[5] = 0x00;
  buf[6] = 0x00;
  buf[7] = 0x00;
  buf[8] = 0x00;
  res = write(ps3_ir, buf, 9);
  if (res < 0) {
    printf("Error: %d\n", errno);
    perror("write");
  } else {
    printf("write() wrote %d bytes\n", res);
  }
  res = read(ps3_ir, buf, 16);
  if (res < 0) {
    perror("read");
  } else {
    printf("read() read %d bytes:\n\t", res);
    for (i = 0; i < res; i++)
      printf("%hhx ", buf[i]);
    puts("\n");
  }
  buf[0] = 0x00;
  buf[1] = 0x00;
  buf[2] = 0xA5;
  buf[3] = mode;
  buf[4] = 0x00;
  buf[5] = 0x00;
  buf[6] = 0x00;
  buf[7] = 0x00;
  buf[8] = 0x00;
  res = write(ps3_ir, buf, 9);
  if (res < 0) {
    printf("Error: %d\n", errno);
    perror("write");
  } else {
    printf("write() wrote %d bytes\n", res);
  }
  res = read(ps3_ir, buf, 16);
  if (res < 0) {
    perror("read");
  } else {
    printf("read() read %d bytes:\n\t", res);
    for (i = 0; i < res; i++)
      printf("%hhx ", buf[i]);
    puts("\n");
  }
  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);
  }
  return;
}


x86 assembly (clang, -O0):
<ps3_set_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <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   1040 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11e9 <ps3_set_mode+0x89>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe2c(%rip),%rdi
call   1080 <perror@plt>
jmp    11f8 <ps3_set_mode+0x98>
mov    -0x10(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x1f(%rbp)
movb   $0xa6,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
movb   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
movb   $0x0,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1260 <ps3_set_mode+0x100>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0xdb6(%rip),%rdi
call   1050 <printf@plt>
lea    0xdb5(%rip),%rdi
call   1080 <perror@plt>
jmp    126f <ps3_set_mode+0x10f>
mov    -0x10(%rbp),%esi
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    129e <ps3_set_mode+0x13e>
lea    0xd95(%rip),%rdi
call   1080 <perror@plt>
jmp    12ef <ps3_set_mode+0x18f>
mov    -0x10(%rbp),%esi
lea    0xd86(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12e3 <ps3_set_mode+0x183>
movslq -0xc(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12b4 <ps3_set_mode+0x154>
lea    0xd1f(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x1f(%rbp)
movb   $0xa5,-0x1e(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x1d(%rbp)
movb   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
movb   $0x0,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1359 <ps3_set_mode+0x1f9>
mov    0x2ca6(%rip),%rax
mov    (%rax),%esi
lea    0xcbd(%rip),%rdi
call   1050 <printf@plt>
lea    0xcbc(%rip),%rdi
call   1080 <perror@plt>
jmp    1368 <ps3_set_mode+0x208>
mov    -0x10(%rbp),%esi
lea    0xcae(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1397 <ps3_set_mode+0x237>
lea    0xc9c(%rip),%rdi
call   1080 <perror@plt>
jmp    13e8 <ps3_set_mode+0x288>
mov    -0x10(%rbp),%esi
lea    0xc8d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    13dc <ps3_set_mode+0x27c>
movslq -0xc(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xc7d(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    13ad <ps3_set_mode+0x24d>
lea    0xc26(%rip),%rdi
call   1030 <puts@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   1040 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1450 <ps3_set_mode+0x2f0>
mov    0x2baf(%rip),%rax
mov    (%rax),%esi
lea    0xbc6(%rip),%rdi
call   1050 <printf@plt>
lea    0xbc5(%rip),%rdi
call   1080 <perror@plt>
jmp    145f <ps3_set_mode+0x2ff>
mov    -0x10(%rbp),%esi
lea    0xbb7(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps3_set_mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%r13d
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movabs $0x99665aa55500aa00,%r15
5a 66 99
mov    %r15,(%rsp)
movb   $0x69,0x8(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x9,%edx
call   1040 <write@plt>
test   %eax,%eax
js     134f <ps3_set_mode+0x1ef>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
movw   $0x0,(%rsp)
movb   $0xa6,0x2(%rsp)
movw   $0x0,0x7(%rbp)
movl   $0x0,0x3(%rbp)
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x9,%edx
call   1040 <write@plt>
test   %eax,%eax
js     1375 <ps3_set_mode+0x215>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
lea    0x4(%rsp),%r12
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x10,%edx
call   1070 <read@plt>
test   %eax,%eax
js     139b <ps3_set_mode+0x23b>
mov    %eax,%ebp
lea    0xe0b(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
je     1256 <ps3_set_mode+0xf6>
mov    %ebp,%ebx
xor    %r15d,%r15d
lea    0xe0c(%rip),%rbp
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%r15,1),%esi
mov    %rbp,%rdi
call   1050 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbx
jne    1240 <ps3_set_mode+0xe0>
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
movabs $0x99665aa55500aa00,%r15
5a 66 99
movw   $0x0,(%rsp)
movb   $0xa5,0x2(%rsp)
mov    %r14b,0x3(%rsp)
movb   $0x0,0x4(%r12)
movl   $0x0,(%r12)
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x9,%edx
call   1040 <write@plt>
test   %eax,%eax
js     13ac <ps3_set_mode+0x24c>
lea    0xd68(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x10,%edx
call   1070 <read@plt>
test   %eax,%eax
js     13d2 <ps3_set_mode+0x272>
mov    %eax,%ebp
lea    0xd5d(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
je     1305 <ps3_set_mode+0x1a5>
mov    %ebp,%ebx
xor    %ebp,%ebp
lea    0xd5f(%rip),%r14
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%rbp,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12f0 <ps3_set_mode+0x190>
lea    0xcfd(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,(%rsp)
movb   $0x69,0x8(%rsp)
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0x9,%edx
call   1040 <write@plt>
test   %eax,%eax
js     13e3 <ps3_set_mode+0x283>
lea    0xcd8(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
lea    0xca1(%rip),%rdi
call   1050 <printf@plt>
lea    0xca0(%rip),%rdi
call   1080 <perror@plt>
jmp    11bf <ps3_set_mode+0x5f>
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
lea    0xc7b(%rip),%rdi
call   1050 <printf@plt>
lea    0xc7a(%rip),%rdi
call   1080 <perror@plt>
jmp    11fd <ps3_set_mode+0x9d>
lea    0xc87(%rip),%rdi
call   1080 <perror@plt>
jmp    126c <ps3_set_mode+0x10c>
mov    0x2c2d(%rip),%rax
mov    (%rax),%esi
lea    0xc44(%rip),%rdi
call   1050 <printf@plt>
lea    0xc43(%rip),%rdi
call   1080 <perror@plt>
jmp    12b0 <ps3_set_mode+0x150>
lea    0xc50(%rip),%rdi
call   1080 <perror@plt>
jmp    1311 <ps3_set_mode+0x1b1>
mov    0x2bf6(%rip),%rax
mov    (%rax),%esi
lea    0xc0d(%rip),%rdi
call   1050 <printf@plt>
lea    0xc0c(%rip),%rdi
call   1080 <perror@plt>
jmp    1340 <ps3_set_mode+0x1e0>

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"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [24 x i8] c"read() read %d bytes:\0A\09\00"
@.str.5 = [6 x i8] c"%hhx \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @ps3_set_mode(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i8]
store i32 %0, i32* %3
store i8 %1, i8* %4
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 16)
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 1
store i8 -86, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 2
store i8 0, i8* %12
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 3
store i8 85, i8* %13
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 4
store i8 -91, i8* %14
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 5
store i8 90, i8* %15
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 6
store i8 102, i8* %16
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 7
store i8 -103, i8* %17
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 8
store i8 105, i8* %18
%19 = load i32, i32* %3
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 9)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* @errno
%26 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
28: ; preds = %2
%29 = load i32, i32* %6
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %24
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8 0, i8* %32
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 1
store i8 0, i8* %33
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 2
store i8 -90, i8* %34
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 3
store i8 0, i8* %35
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 4
store i8 0, i8* %36
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 5
store i8 0, i8* %37
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 6
store i8 0, i8* %38
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 7
store i8 0, i8* %39
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 8
store i8 0, i8* %40
%41 = load i32, i32* %3
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%43 = call i32 @write(i32 %41, i8* %42, i32 9)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %31
%47 = load i32, i32* @errno
%48 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %53
50: ; preds = %31
%51 = load i32, i32* %6
%52 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %46
%54 = load i32, i32* %3
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%56 = call i32 @read(i32 %54, i8* %55, i32 16)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %80
61: ; preds = %53
%62 = load i32, i32* %6
%63 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %62)
store i32 0, i32* %5
br label %64
64: ; preds = %75, %61
%65 = load i32, i32* %5
%66 = load i32, i32* %6
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %78
68: ; preds = %64
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %68
%76 = load i32, i32* %5
%77 = add nsw i32 %76, 1
store i32 %77, i32* %5
br label %64
78: ; preds = %64
%79 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %80
80: ; preds = %78, %59
%81 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8 0, i8* %81
%82 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 1
store i8 0, i8* %82
%83 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 2
store i8 -91, i8* %83
%84 = load i8, i8* %4
%85 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 3
store i8 %84, i8* %85
%86 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 4
store i8 0, i8* %86
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 5
store i8 0, i8* %87
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 6
store i8 0, i8* %88
%89 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 7
store i8 0, i8* %89
%90 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 8
store i8 0, i8* %90
%91 = load i32, i32* %3
%92 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%93 = call i32 @write(i32 %91, i8* %92, i32 9)
store i32 %93, i32* %6
%94 = load i32, i32* %6
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %80
%97 = load i32, i32* @errno
%98 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %97)
%99 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %103
100: ; preds = %80
%101 = load i32, i32* %6
%102 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %100, %96
%104 = load i32, i32* %3
%105 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%106 = call i32 @read(i32 %104, i8* %105, i32 16)
store i32 %106, i32* %6
%107 = load i32, i32* %6
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %103
%110 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %130
111: ; preds = %103
%112 = load i32, i32* %6
%113 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %112)
store i32 0, i32* %5
br label %114
114: ; preds = %125, %111
%115 = load i32, i32* %5
%116 = load i32, i32* %6
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %128
118: ; preds = %114
%119 = load i32, i32* %5
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %120
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %123)
br label %125
125: ; preds = %118
%126 = load i32, i32* %5
%127 = add nsw i32 %126, 1
store i32 %127, i32* %5
br label %114
128: ; preds = %114
%129 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %130
130: ; preds = %128, %109
%131 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8 0, i8* %131
%132 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 1
store i8 -86, i8* %132
%133 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 2
store i8 0, i8* %133
%134 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 3
store i8 85, i8* %134
%135 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 4
store i8 -91, i8* %135
%136 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 5
store i8 90, i8* %136
%137 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 6
store i8 102, i8* %137
%138 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 7
store i8 -103, i8* %138
%139 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 8
store i8 105, i8* %139
%140 = load i32, i32* %3
%141 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%142 = call i32 @write(i32 %140, i8* %141, i32 9)
store i32 %142, i32* %6
%143 = load i32, i32* %6
%144 = icmp slt i32 %143, 0
br i1 %144, label %145, label %149
145: ; preds = %130
%146 = load i32, i32* @errno
%147 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %146)
%148 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %152
149: ; preds = %130
%150 = load i32, i32* %6
%151 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %150)
br label %152
152: ; preds = %149, %145
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"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [24 x i8] c"read() read %d bytes:\0A\09\00"
@.str.5 = [6 x i8] c"%hhx \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @ps3_set_mode(i32 %0, i8 signext %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 16)
store i8 0, i8* %4
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 1
store i8 -86, i8* %6
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 2
store i8 0, i8* %7
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 3
store i8 85, i8* %8
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 4
store i8 -91, i8* %9
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 5
store i8 90, i8* %10
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 6
store i8 102, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 7
store i8 -103, i8* %12
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 8
store i8 105, i8* %13
%14 = call i32 @write(i32 %0, i8* %4, i32 9)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %22
22: ; preds = %20, %16
store i8 0, i8* %4
store i8 0, i8* %6
store i8 -90, i8* %7
%23 = call i32 @write(i32 %0, i8* %4, i32 9)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %31
31: ; preds = %29, %25
%32 = call i32 @read(i32 %0, i8* %4, i32 16)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %51
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%38 = icmp eq i32 %32, 0
br i1 %38, label %49, label %39
39: ; preds = %36
%40 = zext i32 %32 to i64
br label %41
41: ; preds = %39, %41
%42 = phi i64 [ 0, %39 ], [ %47, %41 ]
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i64 %42, 1
%48 = icmp eq i64 %47, %40
br i1 %48, label %49, label %41
49: ; preds = %41, %36
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %49, %34
store i8 0, i8* %4
store i8 0, i8* %6
store i8 -91, i8* %7
store i8 %1, i8* %8
%52 = call i32 @write(i32 %0, i8* %4, i32 9)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* @errno
%56 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %60
58: ; preds = %51
%59 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %60
60: ; preds = %58, %54
%61 = call i32 @read(i32 %0, i8* %4, i32 16)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %80
65: ; preds = %60
%66 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%67 = icmp eq i32 %61, 0
br i1 %67, label %78, label %68
68: ; preds = %65
%69 = zext i32 %61 to i64
br label %70
70: ; preds = %68, %70
%71 = phi i64 [ 0, %68 ], [ %76, %70 ]
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %74)
%76 = add nuw nsw i64 %71, 1
%77 = icmp eq i64 %76, %69
br i1 %77, label %78, label %70
78: ; preds = %70, %65
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %80
80: ; preds = %78, %63
store i8 0, i8* %4
store i8 -86, i8* %6
store i8 0, i8* %7
store i8 85, i8* %8
store i8 -91, i8* %9
store i8 90, i8* %10
store i8 102, i8* %11
store i8 -103, i8* %12
store i8 105, i8* %13
%81 = call i32 @write(i32 %0, i8* %4, i32 9)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i32, i32* @errno
%85 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %84)
%86 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %89
87: ; preds = %80
%88 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %81)
br label %89
89: ; preds = %87, %83
ret void
}