#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 uint8_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int bswap_16(int);
int bswap_32(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int read(int, int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  char path[256];
  char *dot;
  char *eq;
  int fd, size = 4;
  bool do_write = false;
  bool big_endian = false;
  uint32_t addr, val;
  ssize_t rc;
  if (argc < 3) {
    printf("Usage: %s <space> <addr>[.lLwWbBd[,size]][=value]\n", argv[0]);
    return 0;
  }
  eq = strchr(argv[2], '=');
  if (eq) {
    do_write = true;
    val = strtoul(eq + 1, NULL, 0);
    *eq = 0;
  }
  dot = strchr(argv[2], '.');
  if (dot) {
    *(dot++) = 0;
    switch (*dot) {
    case 'L':
      big_endian = true;
    case 'l':
      break;
    case 'W':
      big_endian = true;
    case 'w':
      size = 2;
      break;
    case 'B':
      big_endian = true;
    case 'b':
      size = 1;
      break;
    default:
      fprintf(stderr, "Invalid size specifier\n");
      exit(1);
    }
  }
  addr = strtoul(argv[2], NULL, 0);
  memset(path, 0, sizeof(path));
  snprintf(path, 255,
           "/sys/kernel/debug/powerpc/lpc"
           "/%s",
           argv[1]);
  fd = open(path, O_RDWR);
  if (fd < 0) {
    perror("Failed to open sysfs file");
    exit(1);
  }
  lseek(fd, addr, SEEK_SET);
  if (do_write) {
    uint8_t v8;
    uint16_t v16;
    uint32_t v32;
    switch (size) {
    case 1:
      val &= 0xff;
      v8 = val;
      rc = write(fd, &v8, 1);
      if (rc != 1) {
        perror("Failed to write to LPC");
        exit(1);
      }
      printf("[%s] W 0x%08x.%c=0x%02x\n", argv[1], addr, big_endian ? 'B' : 'b',
             val);
      break;
    case 2:
      val &= 0xffff;
      v16 = big_endian ? bswap_16(val) : val;
      rc = write(fd, &v16, 2);
      if (rc != 2) {
        perror("Failed to write to LPC");
        exit(1);
      }
      printf("[%s] W 0x%08x.%c=0x%04x\n", argv[1], addr, big_endian ? 'W' : 'w',
             val);
      break;
    default:
      v32 = big_endian ? bswap_32(val) : val;
      rc = write(fd, &v32, 4);
      if (rc != 4) {
        perror("Failed to write to LPC");
        exit(1);
      }
      printf("[%s] W 0x%08x.%c=0x%08x\n", argv[1], addr, big_endian ? 'L' : 'l',
             val);
      break;
    }
  } else {
    uint8_t v8;
    uint16_t v16;
    uint32_t v32;
    switch (size) {
    case 1:
      rc = read(fd, &v8, 1);
      if (rc != 1) {
        perror("Failed to read from LPC");
        exit(1);
      }
      printf("[%s] R 0x%08x.%c=0x%02x\n", argv[1], addr, big_endian ? 'B' : 'b',
             v8);
      break;
    case 2:
      rc = read(fd, &v16, 2);
      if (rc != 2) {
        perror("Failed to read from LPC");
        exit(1);
      }
      v16 = big_endian ? bswap_16(v16) : v16;
      printf("[%s] R 0x%08x.%c=0x%04x\n", argv[1], addr, big_endian ? 'W' : 'w',
             v16);
      break;
    default:
      rc = read(fd, &v32, 4);
      if (rc != 4) {
        perror("Failed to read from LPC");
        exit(1);
      }
      v32 = big_endian ? bswap_32(v32) : v32;
      printf("[%s] R 0x%08x.%c=0x%08x\n", argv[1], addr, big_endian ? 'L' : 'l',
             v32);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1242 <main+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1895 <main+0x6b5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     1299 <main+0xb9>
movl   $0x1,-0x12c(%rbp)
mov    -0x120(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,-0x138(%rbp)
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1373 <main+0x193>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x0,(%rax)
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x160(%rbp)
sub    $0x35,%eax
ja     134f <main+0x16f>
mov    -0x160(%rbp),%rax
lea    0xcfb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x130(%rbp)
jmp    136e <main+0x18e>
movl   $0x1,-0x130(%rbp)
movl   $0x2,-0x128(%rbp)
jmp    136e <main+0x18e>
movl   $0x1,-0x130(%rbp)
movl   $0x1,-0x128(%rbp)
jmp    136e <main+0x18e>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1373 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,-0x134(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0xff,%esi
lea    0xd69(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jge    13fd <main+0x21d>
lea    0xd56(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x124(%rbp),%edi
mov    -0x134(%rbp),%esi
mov    0x2bc0(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmpl   $0x0,-0x12c(%rbp)
je     1670 <main+0x490>
mov    -0x128(%rbp),%eax
mov    %eax,-0x164(%rbp)
sub    $0x1,%eax
je     1452 <main+0x272>
jmp    143e <main+0x25e>
mov    -0x164(%rbp),%eax
sub    $0x2,%eax
je     14ed <main+0x30d>
jmp    15b7 <main+0x3d7>
mov    -0x138(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x138(%rbp)
mov    -0x138(%rbp),%eax
mov    %eax,-0x140(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x1,-0x13c(%rbp)
je     14af <main+0x2cf>
lea    0xcbe(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x62,%ecx
mov    $0x42,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x138(%rbp),%r8d
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    166b <main+0x48b>
mov    -0x138(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x138(%rbp)
cmpl   $0x0,-0x130(%rbp)
je     1521 <main+0x341>
mov    -0x138(%rbp),%edi
call   10f0 <bswap_16@plt>
mov    %eax,-0x168(%rbp)
jmp    152d <main+0x34d>
mov    -0x138(%rbp),%eax
mov    %eax,-0x168(%rbp)
mov    -0x168(%rbp),%eax
mov    %eax,-0x144(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x144(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x2,-0x13c(%rbp)
je     1579 <main+0x399>
lea    0xbf4(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x77,%ecx
mov    $0x57,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x138(%rbp),%r8d
lea    0xbe3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    166b <main+0x48b>
cmpl   $0x0,-0x130(%rbp)
je     15da <main+0x3fa>
mov    -0x138(%rbp),%edi
call   10b0 <bswap_32@plt>
mov    %eax,-0x16c(%rbp)
jmp    15e6 <main+0x406>
mov    -0x138(%rbp),%eax
mov    %eax,-0x16c(%rbp)
mov    -0x16c(%rbp),%eax
mov    %eax,-0x148(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x148(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x4,-0x13c(%rbp)
je     1632 <main+0x452>
lea    0xb3b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x6c,%ecx
mov    $0x4c,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x138(%rbp),%r8d
lea    0xb43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    188e <main+0x6ae>
mov    -0x128(%rbp),%eax
mov    %eax,-0x170(%rbp)
sub    $0x1,%eax
je     169e <main+0x4be>
jmp    168a <main+0x4aa>
mov    -0x170(%rbp),%eax
sub    $0x2,%eax
je     171c <main+0x53c>
jmp    17d5 <main+0x5f5>
mov    -0x124(%rbp),%edi
lea    -0x14c(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x1,-0x13c(%rbp)
je     16de <main+0x4fe>
lea    0xaf1(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x62,%ecx
mov    $0x42,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x14c(%rbp),%r8d
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1889 <main+0x6a9>
mov    -0x124(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x2,%edx
call   1090 <read@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x2,-0x13c(%rbp)
je     175c <main+0x57c>
lea    0xa73(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x130(%rbp)
je     177f <main+0x59f>
mov    -0x150(%rbp),%edi
call   10f0 <bswap_16@plt>
mov    %eax,-0x174(%rbp)
jmp    178b <main+0x5ab>
mov    -0x150(%rbp),%eax
mov    %eax,-0x174(%rbp)
mov    -0x174(%rbp),%eax
mov    %eax,-0x150(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x77,%ecx
mov    $0x57,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x150(%rbp),%r8d
lea    0xa28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1889 <main+0x6a9>
mov    -0x124(%rbp),%edi
lea    -0x154(%rbp),%rsi
mov    $0x4,%edx
call   1090 <read@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x4,-0x13c(%rbp)
je     1815 <main+0x635>
lea    0x9ba(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x130(%rbp)
je     1838 <main+0x658>
mov    -0x154(%rbp),%edi
call   10b0 <bswap_32@plt>
mov    %eax,-0x178(%rbp)
jmp    1844 <main+0x664>
mov    -0x154(%rbp),%eax
mov    %eax,-0x178(%rbp)
mov    -0x178(%rbp),%eax
mov    %eax,-0x154(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x134(%rbp),%edx
mov    -0x130(%rbp),%edi
mov    $0x6c,%ecx
mov    $0x4c,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
mov    -0x154(%rbp),%r8d
lea    0x988(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    188e <main+0x6ae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jg     1210 <main+0x30>
mov    (%r12),%rsi
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    14e3 <main+0x303>
mov    0x10(%r12),%rbx
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1246 <main+0x66>
lea    0x1(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,0x4(%rsp)
movb   $0x0,0x0(%rbp)
mov    0x10(%r12),%rbx
jmp    1246 <main+0x66>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    $0x4,%r14d
test   %rax,%rax
je     1292 <main+0xb2>
movb   $0x0,(%rax)
movsbl 0x1(%rax),%eax
add    $0xffffffbe,%eax
cmp    $0x35,%eax
ja     151f <main+0x33f>
xor    %r13d,%r13d
lea    0xd85(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%r13d
mov    $0x1,%r14d
jmp    12ab <main+0xcb>
xor    %r13d,%r13d
jmp    12ab <main+0xcb>
mov    $0x1,%r13d
jmp    12ab <main+0xcb>
mov    $0x1,%r13d
mov    $0x2,%r14d
mov    0x10(%r12),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    0x8(%r12),%rcx
lea    0xe47(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1060 <snprintf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     14f7 <main+0x317>
mov    %eax,%ebx
mov    0x2cc5(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r15d,%esi
call   1070 <lseek@plt>
test   %rbp,%rbp
je     136f <main+0x18f>
cmp    $0x2,%r14d
je     13be <main+0x1de>
cmp    $0x1,%r14d
jne    140b <main+0x22b>
movzbl 0x4(%rsp),%ebp
mov    %ebp,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1500 <main+0x320>
mov    0x8(%r12),%rsi
xor    %ecx,%ecx
test   %r13d,%r13d
sete   %cl
shl    $0x5,%ecx
or     $0x42,%ecx
lea    0xe0b(%rip),%rdi
jmp    1455 <main+0x275>
mov    %rsp,%rsi
mov    %ebx,%edi
cmp    $0x2,%r14d
je     145d <main+0x27d>
cmp    $0x1,%r14d
jne    148b <main+0x2ab>
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    1509 <main+0x329>
mov    0x8(%r12),%rsi
xor    %ecx,%ecx
test   %r13d,%r13d
sete   %cl
shl    $0x5,%ecx
or     $0x42,%ecx
mov    (%rsp),%r8d
lea    0xe1f(%rip),%rdi
jmp    14d9 <main+0x2f9>
movzwl 0x4(%rsp),%ebp
mov    %ebp,%eax
test   %r13d,%r13d
je     13d1 <main+0x1f1>
mov    %ebp,%edi
call   10f0 <bswap_16@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    1500 <main+0x320>
xor    %ecx,%ecx
test   %r13d,%r13d
sete   %cl
mov    0x8(%r12),%rsi
shl    $0x5,%ecx
or     $0x57,%ecx
lea    0xd85(%rip),%rdi
jmp    1455 <main+0x275>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
test   %r13d,%r13d
je     141d <main+0x23d>
mov    %ebp,%edi
call   10b0 <bswap_32@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1500 <main+0x320>
xor    %ecx,%ecx
test   %r13d,%r13d
sete   %cl
mov    0x8(%r12),%rsi
shl    $0x5,%ecx
or     $0x4c,%ecx
lea    0xd52(%rip),%rdi
mov    %r15d,%edx
mov    %ebp,%r8d
jmp    14dc <main+0x2fc>
mov    $0x2,%edx
call   1090 <read@plt>
cmp    $0x2,%eax
jne    1509 <main+0x329>
mov    (%rsp),%r8d
test   %r13d,%r13d
je     14b5 <main+0x2d5>
mov    %r8d,%edi
call   10f0 <bswap_16@plt>
mov    %eax,%r8d
mov    $0x57,%ecx
jmp    14ba <main+0x2da>
mov    $0x4,%edx
call   1090 <read@plt>
cmp    $0x4,%eax
jne    1509 <main+0x329>
mov    (%rsp),%r8d
test   %r13d,%r13d
je     14c8 <main+0x2e8>
mov    %r8d,%edi
call   10b0 <bswap_32@plt>
mov    %eax,%r8d
mov    $0x4c,%ecx
jmp    14cd <main+0x2ed>
mov    $0x77,%ecx
mov    0x8(%r12),%rsi
lea    0xd2b(%rip),%rdi
jmp    14d9 <main+0x2f9>
mov    $0x6c,%ecx
mov    0x8(%r12),%rsi
lea    0xd31(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc46(%rip),%rdi
jmp    1510 <main+0x330>
lea    0xc57(%rip),%rdi
jmp    1510 <main+0x330>
lea    0xcb0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2ab2(%rip),%rax
mov    (%rax),%edi
lea    0xbdc(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"Usage: %s <space> <addr>[.lLwWbBd[,size]][=value]\0A\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Invalid size specifier\0A\00"
@.str.2 = [33 x i8] c"/sys/kernel/debug/powerpc/lpc/%s\00"
@O_RDWR = global i32 0
@.str.3 = [26 x i8] c"Failed to open sysfs file\00"
@SEEK_SET = global i32 0
@.str.4 = [23 x i8] c"Failed to write to LPC\00"
@.str.5 = [25 x i8] c"[%s] W 0x%08x.%c=0x%02x\0A\00"
@.str.6 = [25 x i8] c"[%s] W 0x%08x.%c=0x%04x\0A\00"
@.str.7 = [25 x i8] c"[%s] W 0x%08x.%c=0x%08x\0A\00"
@.str.8 = [24 x i8] c"Failed to read from LPC\00"
@.str.9 = [25 x i8] c"[%s] R 0x%08x.%c=0x%02x\0A\00"
@.str.10 = [25 x i8] c"[%s] R 0x%08x.%c=0x%04x\0A\00"
@.str.11 = [25 x i8] c"[%s] R 0x%08x.%c=0x%08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %29
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 0, i32* %3
br label %254
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @strchr(i8* %32, i8 signext 61)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %29
store i32 1, i32* %11
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i32 @strtoul(i8* %38, i32* null, i32 0)
store i32 %39, i32* %14
%40 = load i8*, i8** %8
store i8 0, i8* %40
br label %41
41: ; preds = %36, %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i8* @strchr(i8* %44, i8 signext 46)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %65
48: ; preds = %41
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %7
store i8 0, i8* %49
%51 = load i8*, i8** %7
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
switch i32 %53, label %60 [
i32 76, label %54
i32 108, label %55
i32 87, label %56
i32 119, label %57
i32 66, label %58
i32 98, label %59
]
54: ; preds = %48
store i32 1, i32* %12
br label %55
55: ; preds = %48, %54
br label %64
56: ; preds = %48
store i32 1, i32* %12
br label %57
57: ; preds = %48, %56
store i32 2, i32* %10
br label %64
58: ; preds = %48
store i32 1, i32* %12
br label %59
59: ; preds = %48, %58
store i32 1, i32* %10
br label %64
60: ; preds = %48
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %59, %57, %55
br label %65
65: ; preds = %64, %41
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @strtoul(i8* %68, i32* null, i32 0)
store i32 %69, i32* %13
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%71 = call i32 @memset(i8* %70, i32 0, i32 256)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i32 @snprintf(i8* %72, i32 255, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %75)
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%78 = load i32, i32* @O_RDWR
%79 = call i32 @open(i8* %77, i32 %78)
store i32 %79, i32* %9
%80 = load i32, i32* %9
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %65
%83 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %65
%86 = load i32, i32* %9
%87 = load i32, i32* %13
%88 = load i32, i32* @SEEK_SET
%89 = call i32 @lseek(i32 %86, i32 %87, i32 %88)
%90 = load i32, i32* %11
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %175
92: ; preds = %85
%93 = load i32, i32* %10
switch i32 %93, label %146 [
i32 1, label %94
i32 2, label %116
]
94: ; preds = %92
%95 = load i32, i32* %14
%96 = and i32 %95, 255
store i32 %96, i32* %14
%97 = load i32, i32* %14
store i32 %97, i32* %16
%98 = load i32, i32* %9
%99 = call i32 @write(i32 %98, i32* %16, i32 1)
store i32 %99, i32* %15
%100 = load i32, i32* %15
%101 = icmp ne i32 %100, 1
br i1 %101, label %102, label %105
102: ; preds = %94
%103 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %94
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 1
%108 = load i8*, i8** %107
%109 = load i32, i32* %13
%110 = load i32, i32* %12
%111 = icmp ne i32 %110, 0
%112 = zext i1 %111 to i64
%113 = select i1 %111, i32 66, i32 98
%114 = load i32, i32* %14
%115 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %108, i32 %109, i32 %113, i32 %114)
br label %174
116: ; preds = %92
%117 = load i32, i32* %14
%118 = and i32 %117, 65535
store i32 %118, i32* %14
%119 = load i32, i32* %12
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %124
121: ; preds = %116
%122 = load i32, i32* %14
%123 = call i32 @bswap_16(i32 %122)
br label %126
124: ; preds = %116
%125 = load i32, i32* %14
br label %126
126: ; preds = %124, %121
%127 = phi i32 [ %123, %121 ], [ %125, %124 ]
store i32 %127, i32* %17
%128 = load i32, i32* %9
%129 = call i32 @write(i32 %128, i32* %17, i32 2)
store i32 %129, i32* %15
%130 = load i32, i32* %15
%131 = icmp ne i32 %130, 2
br i1 %131, label %132, label %135
132: ; preds = %126
%133 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%134 = call i32 @exit(i32 1)
unreachable
135: ; preds = %126
%136 = load i8**, i8*** %5
%137 = getelementptr inbounds i8*, i8** %136, i64 1
%138 = load i8*, i8** %137
%139 = load i32, i32* %13
%140 = load i32, i32* %12
%141 = icmp ne i32 %140, 0
%142 = zext i1 %141 to i64
%143 = select i1 %141, i32 87, i32 119
%144 = load i32, i32* %14
%145 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %138, i32 %139, i32 %143, i32 %144)
br label %174
146: ; preds = %92
%147 = load i32, i32* %12
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %152
149: ; preds = %146
%150 = load i32, i32* %14
%151 = call i32 @bswap_32(i32 %150)
br label %154
152: ; preds = %146
%153 = load i32, i32* %14
br label %154
154: ; preds = %152, %149
%155 = phi i32 [ %151, %149 ], [ %153, %152 ]
store i32 %155, i32* %18
%156 = load i32, i32* %9
%157 = call i32 @write(i32 %156, i32* %18, i32 4)
store i32 %157, i32* %15
%158 = load i32, i32* %15
%159 = icmp ne i32 %158, 4
br i1 %159, label %160, label %163
160: ; preds = %154
%161 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %154
%164 = load i8**, i8*** %5
%165 = getelementptr inbounds i8*, i8** %164, i64 1
%166 = load i8*, i8** %165
%167 = load i32, i32* %13
%168 = load i32, i32* %12
%169 = icmp ne i32 %168, 0
%170 = zext i1 %169 to i64
%171 = select i1 %169, i32 76, i32 108
%172 = load i32, i32* %14
%173 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %166, i32 %167, i32 %171, i32 %172)
br label %174
174: ; preds = %163, %135, %105
br label %253
175: ; preds = %85
%176 = load i32, i32* %10
switch i32 %176, label %224 [
i32 1, label %177
i32 2, label %196
]
177: ; preds = %175
%178 = load i32, i32* %9
%179 = call i32 @read(i32 %178, i32* %19, i32 1)
store i32 %179, i32* %15
%180 = load i32, i32* %15
%181 = icmp ne i32 %180, 1
br i1 %181, label %182, label %185
182: ; preds = %177
%183 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%184 = call i32 @exit(i32 1)
unreachable
185: ; preds = %177
%186 = load i8**, i8*** %5
%187 = getelementptr inbounds i8*, i8** %186, i64 1
%188 = load i8*, i8** %187
%189 = load i32, i32* %13
%190 = load i32, i32* %12
%191 = icmp ne i32 %190, 0
%192 = zext i1 %191 to i64
%193 = select i1 %191, i32 66, i32 98
%194 = load i32, i32* %19
%195 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %188, i32 %189, i32 %193, i32 %194)
br label %252
196: ; preds = %175
%197 = load i32, i32* %9
%198 = call i32 @read(i32 %197, i32* %20, i32 2)
store i32 %198, i32* %15
%199 = load i32, i32* %15
%200 = icmp ne i32 %199, 2
br i1 %200, label %201, label %204
201: ; preds = %196
%202 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%203 = call i32 @exit(i32 1)
unreachable
204: ; preds = %196
%205 = load i32, i32* %12
%206 = icmp ne i32 %205, 0
br i1 %206, label %207, label %210
207: ; preds = %204
%208 = load i32, i32* %20
%209 = call i32 @bswap_16(i32 %208)
br label %212
210: ; preds = %204
%211 = load i32, i32* %20
br label %212
212: ; preds = %210, %207
%213 = phi i32 [ %209, %207 ], [ %211, %210 ]
store i32 %213, i32* %20
%214 = load i8**, i8*** %5
%215 = getelementptr inbounds i8*, i8** %214, i64 1
%216 = load i8*, i8** %215
%217 = load i32, i32* %13
%218 = load i32, i32* %12
%219 = icmp ne i32 %218, 0
%220 = zext i1 %219 to i64
%221 = select i1 %219, i32 87, i32 119
%222 = load i32, i32* %20
%223 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %216, i32 %217, i32 %221, i32 %222)
br label %252
224: ; preds = %175
%225 = load i32, i32* %9
%226 = call i32 @read(i32 %225, i32* %21, i32 4)
store i32 %226, i32* %15
%227 = load i32, i32* %15
%228 = icmp ne i32 %227, 4
br i1 %228, label %229, label %232
229: ; preds = %224
%230 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%231 = call i32 @exit(i32 1)
unreachable
232: ; preds = %224
%233 = load i32, i32* %12
%234 = icmp ne i32 %233, 0
br i1 %234, label %235, label %238
235: ; preds = %232
%236 = load i32, i32* %21
%237 = call i32 @bswap_32(i32 %236)
br label %240
238: ; preds = %232
%239 = load i32, i32* %21
br label %240
240: ; preds = %238, %235
%241 = phi i32 [ %237, %235 ], [ %239, %238 ]
store i32 %241, i32* %21
%242 = load i8**, i8*** %5
%243 = getelementptr inbounds i8*, i8** %242, i64 1
%244 = load i8*, i8** %243
%245 = load i32, i32* %13
%246 = load i32, i32* %12
%247 = icmp ne i32 %246, 0
%248 = zext i1 %247 to i64
%249 = select i1 %247, i32 76, i32 108
%250 = load i32, i32* %21
%251 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %244, i32 %245, i32 %249, i32 %250)
br label %252
252: ; preds = %240, %212, %185
br label %253
253: ; preds = %252, %174
store i32 0, i32* %3
br label %254
254: ; preds = %253, %24
%255 = load i32, i32* %3
ret i32 %255
}

LLVM IR (-O2):
@.str = [51 x i8] c"Usage: %s <space> <addr>[.lLwWbBd[,size]][=value]\0A\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Invalid size specifier\0A\00"
@.str.2 = [33 x i8] c"/sys/kernel/debug/powerpc/lpc/%s\00"
@O_RDWR = global i32 0
@.str.3 = [26 x i8] c"Failed to open sysfs file\00"
@SEEK_SET = global i32 0
@.str.4 = [23 x i8] c"Failed to write to LPC\00"
@.str.5 = [25 x i8] c"[%s] W 0x%08x.%c=0x%02x\0A\00"
@.str.6 = [25 x i8] c"[%s] W 0x%08x.%c=0x%04x\0A\00"
@.str.7 = [25 x i8] c"[%s] W 0x%08x.%c=0x%08x\0A\00"
@.str.8 = [24 x i8] c"Failed to read from LPC\00"
@.str.9 = [25 x i8] c"[%s] R 0x%08x.%c=0x%02x\0A\00"
@.str.10 = [25 x i8] c"[%s] R 0x%08x.%c=0x%04x\0A\00"
@.str.11 = [25 x i8] c"[%s] R 0x%08x.%c=0x%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %159
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 61)
%19 = icmp eq i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = tail call i32 @strtoul(i8* nocapture %21, i32* null, i32 0)
store i8 0, i8* %18
%23 = load i8*, i8** %16
br label %24
24: ; preds = %20, %15
%25 = phi i8* [ %23, %20 ], [ %17, %15 ]
%26 = phi i32 [ %22, %20 ], [ undef, %15 ]
%27 = tail call i8* @strchr(i8* dereferenceable(1) %25, i8 signext 46)
%28 = icmp eq i8* %27, null
br i1 %28, label %44, label %29
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %27, i64 1
store i8 0, i8* %27
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
switch i32 %32, label %40 [
i32 76, label %33
i32 108, label %44
i32 87, label %34
i32 119, label %35
i32 66, label %37
i32 98, label %38
]
33: ; preds = %29
br label %44
34: ; preds = %29
br label %35
35: ; preds = %29, %34
%36 = phi i32 [ 0, %29 ], [ 1, %34 ]
br label %44
37: ; preds = %29
br label %38
38: ; preds = %29, %37
%39 = phi i32 [ 0, %29 ], [ 1, %37 ]
br label %44
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %29, %33, %35, %38, %24
%45 = phi i32 [ 1, %38 ], [ 2, %35 ], [ 4, %29 ], [ 4, %33 ], [ 4, %24 ]
%46 = phi i32 [ %39, %38 ], [ %36, %35 ], [ 0, %29 ], [ 1, %33 ], [ 0, %24 ]
%47 = load i8*, i8** %16
%48 = tail call i32 @strtoul(i8* nocapture %47, i32* null, i32 0)
%49 = call i32 @memset(i8* %10, i32 0, i32 256)
%50 = getelementptr inbounds i8*, i8** %1, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @snprintf(i8* %10, i32 255, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @O_RDWR
%54 = call i32 @open(i8* %10, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %44
%57 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %44
%60 = load i32, i32* @SEEK_SET
%61 = call i32 @lseek(i32 %54, i32 %48, i32 %60)
br i1 %19, label %110, label %62
62: ; preds = %59
%63 = bitcast i32* %4 to i8*
%64 = bitcast i32* %5 to i8*
%65 = bitcast i32* %6 to i8*
switch i32 %45, label %94 [
i32 1, label %66
i32 2, label %78
]
66: ; preds = %62
%67 = and i32 %26, 255
store i32 %67, i32* %4
%68 = call i32 @write(i32 %54, i32* %4, i32 1)
%69 = icmp eq i32 %68, 1
br i1 %69, label %73, label %70
70: ; preds = %66
%71 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %66
%74 = load i8*, i8** %50
%75 = icmp eq i32 %46, 0
%76 = select i1 %75, i32 98, i32 66
%77 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %74, i32 %48, i32 %76, i32 %67)
br label %109
78: ; preds = %62
%79 = and i32 %26, 65535
%80 = icmp eq i32 %46, 0
br i1 %80, label %83, label %81
81: ; preds = %78
%82 = call i32 @bswap_16(i32 %79)
br label %83
83: ; preds = %78, %81
%84 = phi i32 [ %82, %81 ], [ %79, %78 ]
store i32 %84, i32* %5
%85 = call i32 @write(i32 %54, i32* %5, i32 2)
%86 = icmp eq i32 %85, 2
br i1 %86, label %90, label %87
87: ; preds = %83
%88 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %83
%91 = load i8*, i8** %50
%92 = select i1 %80, i32 119, i32 87
%93 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %91, i32 %48, i32 %92, i32 %79)
br label %109
94: ; preds = %62
%95 = icmp eq i32 %46, 0
br i1 %95, label %98, label %96
96: ; preds = %94
%97 = call i32 @bswap_32(i32 %26)
br label %98
98: ; preds = %94, %96
%99 = phi i32 [ %97, %96 ], [ %26, %94 ]
store i32 %99, i32* %6
%100 = call i32 @write(i32 %54, i32* %6, i32 4)
%101 = icmp eq i32 %100, 4
br i1 %101, label %105, label %102
102: ; preds = %98
%103 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %98
%106 = load i8*, i8** %50
%107 = select i1 %95, i32 108, i32 76
%108 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %106, i32 %48, i32 %107, i32 %26)
br label %109
109: ; preds = %105, %90, %73
br label %159
110: ; preds = %59
%111 = bitcast i32* %7 to i8*
%112 = bitcast i32* %8 to i8*
%113 = bitcast i32* %9 to i8*
switch i32 %45, label %142 [
i32 1, label %114
i32 2, label %126
]
114: ; preds = %110
%115 = call i32 @read(i32 %54, i32* %7, i32 1)
%116 = icmp eq i32 %115, 1
br i1 %116, label %120, label %117
117: ; preds = %114
%118 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %114
%121 = load i8*, i8** %50
%122 = icmp eq i32 %46, 0
%123 = select i1 %122, i32 98, i32 66
%124 = load i32, i32* %7
%125 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %121, i32 %48, i32 %123, i32 %124)
br label %158
126: ; preds = %110
%127 = call i32 @read(i32 %54, i32* %8, i32 2)
%128 = icmp eq i32 %127, 2
br i1 %128, label %132, label %129
129: ; preds = %126
%130 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %126
%133 = icmp eq i32 %46, 0
%134 = load i32, i32* %8
br i1 %133, label %137, label %135
135: ; preds = %132
%136 = call i32 @bswap_16(i32 %134)
br label %137
137: ; preds = %132, %135
%138 = phi i32 [ 87, %135 ], [ 119, %132 ]
%139 = phi i32 [ %136, %135 ], [ %134, %132 ]
%140 = load i8*, i8** %50
%141 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %140, i32 %48, i32 %138, i32 %139)
br label %158
142: ; preds = %110
%143 = call i32 @read(i32 %54, i32* %9, i32 4)
%144 = icmp eq i32 %143, 4
br i1 %144, label %148, label %145
145: ; preds = %142
%146 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %142
%149 = icmp eq i32 %46, 0
%150 = load i32, i32* %9
br i1 %149, label %153, label %151
151: ; preds = %148
%152 = call i32 @bswap_32(i32 %150)
br label %153
153: ; preds = %148, %151
%154 = phi i32 [ 76, %151 ], [ 108, %148 ]
%155 = phi i32 [ %152, %151 ], [ %150, %148 ]
%156 = load i8*, i8** %50
%157 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %156, i32 %48, i32 %154, i32 %155)
br label %158
158: ; preds = %153, %137, %120
br label %159
159: ; preds = %109, %158, %12
ret i32 0
}