#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 */
struct option {
  char *name;
  int has_arg;
  char val;
  int /*<<< orphan*/ *flag;
};
struct jedec {
  int dummy;
};
struct chip {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ chip_close(struct chip *);
int chip_diagnose(struct chip *);
int chip_erase(struct chip *);
struct chip *chip_open(char const *, char const *);
int chip_program(struct chip *, struct jedec *);
int chip_verify(struct chip *, struct jedec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int getopt_long(int, char **, char *, struct option const *, int *);
struct jedec *jedec_read(int);
int open(char const *, int /*<<< orphan*/);
char *optarg;
int optind;
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  struct jedec *jed;
  struct chip *chip;
  int err;
  int c;
  const char *jedec = NULL;
  const char *chip_name = NULL;
  const char *tool_name = NULL;
  int option;
  enum {
    MODE_INVALID = 0,
    MODE_CHECK,
    MODE_ERASE,
    MODE_PROGRAM,
    MODE_VERIFY,
  } mode;
  const struct option options[] = {
      {.name = "chip", .has_arg = (!(0)), .flag = NULL, .val = 'c'},
      {.name = "tool", .has_arg = (!(0)), .flag = NULL, .val = 't'},
      {.name = "help", .has_arg = (0), .flag = NULL, .val = 'h'},
      {.name = NULL},
  };
  while ((c = getopt_long(argc, argv, "+c:t:h", options, &option)) >= 0) {
    switch (c) {
    case 'c':
      chip_name = optarg;
      break;
    case 't':
      tool_name = optarg;
      break;
    default:
      usage(argv[0]);
      break;
    }
  }
  mode = MODE_INVALID;
  if (optind == argc) {
    mode = MODE_CHECK;
  } else if ((argc - optind) == 1) {
    if (strcmp(argv[optind], "check") == 0) {
      mode = MODE_CHECK;
    } else if (strcmp(argv[optind], "erase") == 0) {
      mode = MODE_ERASE;
    }
  } else if ((argc - optind) == 2) {
    if (strcmp(argv[optind], "program") == 0) {
      mode = MODE_PROGRAM;
      jedec = argv[optind + 1];
    } else if (strcmp(argv[optind], "verify") == 0) {
      mode = MODE_VERIFY;
      jedec = argv[optind + 1];
    }
  }
  if (mode == MODE_INVALID)
    usage(argv[0]);
  chip = chip_open(chip_name, tool_name);
  assert(chip != NULL);
  fprintf(stderr, "%s:%s Check...\n", chip_name, tool_name);
  err = chip_diagnose(chip);
  if (err < 0) {
    fprintf(stderr, "%s:%s Functionality check failed\n", chip_name, tool_name);
    chip_close(chip);
    return EXIT_FAILURE;
  }
  if (mode == MODE_CHECK) {
    chip_close(chip);
    return EXIT_SUCCESS;
  }
  if (mode != MODE_ERASE) {
    if (jedec == NULL) {
      fprintf(stderr, "%s:%s No JEDEC fuse map specified for this operation\n",
              chip_name, tool_name);
      chip_close(chip);
      return EXIT_FAILURE;
    }
    if (strcmp(jedec, "-") == 0)
      jedec = "/dev/stdin";
    err = open(jedec, O_RDONLY);
    if (err < 0) {
      fprintf(stderr, "%s: %s\n", jedec, strerror(errno));
      chip_close(chip);
      return EXIT_FAILURE;
    }
    jed = jedec_read(err);
    close(err);
    if (jed == NULL) {
      fprintf(stderr, "%s: Invalid JEDEC file\n", jedec);
      chip_close(chip);
      return EXIT_FAILURE;
    }
  }
  if (mode == MODE_VERIFY)
    goto verify;
  fprintf(stderr, "%s:%s Erase...\n", chip_name, tool_name);
  err = chip_erase(chip);
  if (err < 0) {
    fprintf(stderr, "%s:%s Erase failed\n", chip_name, tool_name);
    chip_close(chip);
    return EXIT_FAILURE;
  }
  if (mode == MODE_ERASE) {
    chip_close(chip);
    return EXIT_SUCCESS;
  }
  fprintf(stderr, "%s:%s Program...\n", chip_name, tool_name);
  err = chip_program(chip, jed);
  if (err < 0) {
    fprintf(stderr, "%s:%s Programming failed\n", chip_name, tool_name);
    chip_close(chip);
    return EXIT_FAILURE;
  }
verify:
  fprintf(stderr, "%s:%s Verify...\n", chip_name, tool_name);
  err = chip_verify(chip, jed);
  if (err < 0) {
    fprintf(stderr, "%s:%s Verify failed\n", chip_name, tool_name);
    chip_close(chip);
    return EXIT_FAILURE;
  }
  chip_close(chip);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0x2b41(%rip),%rsi
mov    $0x60,%edx
call   10d0 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0xb0(%rbp),%rcx
lea    0xdb1(%rip),%rdx
lea    -0x44(%rbp),%r8
call   1060 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jl     12d5 <main+0xd5>
mov    -0x28(%rbp),%eax
mov    %eax,-0xb4(%rbp)
sub    $0x63,%eax
je     129e <main+0x9e>
jmp    128a <main+0x8a>
mov    -0xb4(%rbp),%eax
sub    $0x74,%eax
je     12b1 <main+0xb1>
jmp    12c4 <main+0xc4>
mov    0x2d4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    12d0 <main+0xd0>
mov    0x2d38(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12d0 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    1249 <main+0x49>
movl   $0x0,-0x48(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    12fa <main+0xfa>
movl   $0x1,-0x48(%rbp)
jmp    143e <main+0x23e>
mov    -0x8(%rbp),%eax
mov    0x2ccc(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jne    137c <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x2cb6(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcee(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1343 <main+0x143>
movl   $0x1,-0x48(%rbp)
jmp    1377 <main+0x177>
mov    -0x10(%rbp),%rax
mov    0x2c82(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcc0(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1372 <main+0x172>
movl   $0x2,-0x48(%rbp)
jmp    1377 <main+0x177>
jmp    1439 <main+0x239>
mov    -0x8(%rbp),%eax
mov    0x2c4a(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jne    1434 <main+0x234>
mov    -0x10(%rbp),%rax
mov    0x2c34(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc78(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    13e0 <main+0x1e0>
movl   $0x3,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c05(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    142f <main+0x22f>
mov    -0x10(%rbp),%rax
mov    0x2be5(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc31(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    142a <main+0x22a>
movl   $0x4,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2bb6(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    142f <main+0x22f>
jmp    1434 <main+0x234>
jmp    1439 <main+0x239>
jmp    143e <main+0x23e>
cmpl   $0x0,-0x48(%rbp)
jne    1454 <main+0x254>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <chip_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xba2(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <chip_diagnose@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    14e5 <main+0x2e5>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xb7d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x2ad5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
cmpl   $0x1,-0x48(%rbp)
jne    1509 <main+0x309>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x2aa9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
cmpl   $0x2,-0x48(%rbp)
je     1654 <main+0x454>
cmpq   $0x0,-0x30(%rbp)
jne    1557 <main+0x357>
mov    0x2a9b(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xb2d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x2a63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
mov    -0x30(%rbp),%rdi
lea    0xb37(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    157c <main+0x37c>
lea    0xb23(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2a51(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    15fb <main+0x3fb>
mov    0x2a1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x29fc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    %rax,%rcx
lea    0xacc(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x29bf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
mov    -0x24(%rbp),%edi
call   10e0 <jedec_read@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
cmpq   $0x0,-0x18(%rbp)
jne    164f <main+0x44f>
mov    0x299f(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xa80(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x296b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
jmp    1654 <main+0x454>
cmpl   $0x4,-0x48(%rbp)
jne    1663 <main+0x463>
jmp    176c <main+0x56c>
mov    0x2956(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xa4b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1110 <chip_erase@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    16d1 <main+0x4d1>
mov    0x2921(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xa26(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x28e9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
cmpl   $0x2,-0x48(%rbp)
jne    16f5 <main+0x4f5>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x28bd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
mov    0x28c4(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0x9dd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <chip_program@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1767 <main+0x567>
mov    0x288b(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0x9b6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x2853(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
jmp    176c <main+0x56c>
mov    0x284d(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0x992(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <chip_verify@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    17de <main+0x5de>
mov    0x2814(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0x96a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
mov    0x27dc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    17ee <main+0x5ee>
mov    -0x20(%rbp),%rdi
call   1090 <chip_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movaps 0x2bc3(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0x2ba4(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0x2b88(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0x2b6c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2b50(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2b34(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xdb7(%rip),%rdx
lea    0x30(%rsp),%rcx
lea    0x2c(%rsp),%r8
call   1060 <getopt_long@plt>
test   %eax,%eax
js     12eb <main+0xfb>
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
mov    0x2d73(%rip),%r12
lea    0xd8b(%rip),%r15
lea    0x30(%rsp),%r13
lea    0x2c(%rsp),%r14
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
jmp    12bf <main+0xcf>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   10e0 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1060 <getopt_long@plt>
test   %eax,%eax
js     12f9 <main+0x109>
cmp    $0x74,%eax
je     12e0 <main+0xf0>
cmp    $0x63,%eax
jne    12a0 <main+0xb0>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
jmp    12a8 <main+0xb8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
jmp    12a8 <main+0xb8>
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x2cd0(%rip),%r14
movslq (%r14),%rax
mov    $0x1,%r13b
cmp    %ebp,%eax
jne    1325 <main+0x135>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%rbp
jmp    13f3 <main+0x203>
sub    %eax,%ebp
cmp    $0x2,%ebp
je     136f <main+0x17f>
cmp    $0x1,%ebp
mov    0x8(%rsp),%rbp
jne    13a1 <main+0x1b1>
mov    (%rbx,%rax,8),%rdi
lea    0xcd5(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13bf <main+0x1cf>
movslq (%r14),%rax
mov    (%rbx,%rax,8),%rdi
lea    0xcc3(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    13a1 <main+0x1b1>
mov    $0x1,%r12b
xor    %eax,%eax
mov    %rax,0x18(%rsp)
jmp    13b3 <main+0x1c3>
mov    (%rbx,%rax,8),%rdi
lea    0xca8(%rip),%rsi
call   10a0 <strcmp@plt>
movslq (%r14),%rcx
test   %rax,%rax
mov    0x8(%rsp),%rbp
je     13cb <main+0x1db>
mov    (%rbx,%rcx,8),%rdi
lea    0xc93(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13d9 <main+0x1e9>
mov    (%rbx),%rdi
call   10e0 <usage@plt>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    13f3 <main+0x203>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
jmp    13b6 <main+0x1c6>
mov    0x8(%rbx,%rcx,8),%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
jmp    13e8 <main+0x1f8>
movslq (%r14),%rax
mov    0x8(%rbx,%rax,8),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%al
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
mov    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <chip_open@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10b0 <assert@plt>
mov    0x2ba5(%rip),%rbx
mov    (%rbx),%edi
lea    0xc0d(%rip),%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r15,%rdi
call   1070 <chip_diagnose@plt>
test   %eax,%eax
js     1456 <main+0x266>
test   %r13b,%r13b
je     146a <main+0x27a>
mov    %r15,%rdi
call   1090 <chip_close@plt>
mov    0x2b57(%rip),%rax
jmp    1623 <main+0x433>
mov    (%rbx),%edi
lea    0xbe2(%rip),%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
jmp    160d <main+0x41d>
mov    %rbp,%r14
test   %r12b,%r12b
mov    0x20(%rsp),%rdx
mov    %rbx,%rbp
je     14c0 <main+0x2d0>
cmpb   $0x0,0x18(%rsp)
je     1555 <main+0x365>
mov    0x0(%rbp),%edi
lea    0xc87(%rip),%rsi
xor    %ebx,%ebx
mov    %rdx,%r12
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
call   1050 <chip_verify@plt>
test   %eax,%eax
js     15cc <main+0x3dc>
mov    %r15,%rdi
call   1090 <chip_close@plt>
jmp    1625 <main+0x435>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     15c0 <main+0x3d0>
mov    %rdx,0x20(%rsp)
lea    0xbbf(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
lea    0xbaf(%rip),%r13
cmovne %rbx,%r13
mov    0x2ae1(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10f0 <open@plt>
test   %eax,%eax
js     15db <main+0x3eb>
mov    %eax,%ebx
mov    %eax,%edi
call   10d0 <jedec_read@plt>
mov    %r14,%rbp
mov    %rax,%r14
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r14,0x8(%rsp)
test   %r14,%r14
mov    %rbp,%r14
mov    0x2a8f(%rip),%rbp
mov    0x20(%rsp),%rdx
jne    147a <main+0x28a>
mov    0x0(%rbp),%edi
lea    0xb68(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1614 <main+0x424>
mov    0x0(%rbp),%edi
lea    0xb67(%rip),%rsi
mov    %rdx,%rbx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r15,%rdi
call   1100 <chip_erase@plt>
test   %eax,%eax
js     15fd <main+0x40d>
test   %r12b,%r12b
jne    1442 <main+0x252>
mov    0x0(%rbp),%edi
lea    0xb5b(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
call   1040 <chip_program@plt>
mov    %rbx,%rdx
test   %eax,%eax
jns    1485 <main+0x295>
mov    0x0(%rbp),%edi
lea    0xb3e(%rip),%rsi
jmp    160a <main+0x41a>
mov    0x0(%rbp),%edi
lea    0xa99(%rip),%rsi
jmp    160a <main+0x41a>
mov    0x0(%rbp),%edi
lea    0xb51(%rip),%rsi
mov    %r12,%rdx
jmp    160a <main+0x41a>
mov    0x0(%rbp),%ebx
mov    0x29d3(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xab3(%rip),%rsi
mov    %ebx,%edi
mov    %r13,%rdx
mov    %rax,%rcx
jmp    160d <main+0x41d>
mov    0x0(%rbp),%edi
lea    0xacf(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r15,%rdi
call   1090 <chip_close@plt>
mov    0x298d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32* }
%struct.jedec = type { i32 }
%struct.chip = type { i32 }
@.str = [5 x i8] c"chip\00"
@.str.1 = [5 x i8] c"tool\00"
@.str.2 = [5 x i8] c"help\00"
@__const.main.options = [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 1, i8 99, i32* null }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 1, i8 116, i32* null }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 104, i32* null }, %struct.option zeroinitializer]
@.str.3 = [7 x i8] c"+c:t:h\00"
@optarg = global i8* null
@optind = global i32 0
@.str.4 = [6 x i8] c"check\00"
@.str.5 = [6 x i8] c"erase\00"
@.str.6 = [8 x i8] c"program\00"
@.str.7 = [7 x i8] c"verify\00"
@stderr = global i32 0
@.str.8 = [16 x i8] c"%s:%s Check...\0A\00"
@.str.9 = [34 x i8] c"%s:%s Functionality check failed\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.10 = [54 x i8] c"%s:%s No JEDEC fuse map specified for this operation\0A\00"
@.str.11 = [2 x i8] c"-\00"
@.str.12 = [11 x i8] c"/dev/stdin\00"
@O_RDONLY = global i32 0
@.str.13 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.14 = [24 x i8] c"%s: Invalid JEDEC file\0A\00"
@.str.15 = [16 x i8] c"%s:%s Erase...\0A\00"
@.str.16 = [20 x i8] c"%s:%s Erase failed\0A\00"
@.str.17 = [18 x i8] c"%s:%s Program...\0A\00"
@.str.18 = [26 x i8] c"%s:%s Programming failed\0A\00"
@.str.19 = [17 x i8] c"%s:%s Verify...\0A\00"
@.str.20 = [21 x i8] c"%s:%s Verify failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.jedec*
%7 = alloca %struct.chip*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca [4 x %struct.option]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %11
store i8* null, i8** %12
%16 = bitcast [4 x %struct.option]* %15 to i8*
br label %17
17: ; preds = %34, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds [4 x %struct.option], [4 x %struct.option]* %15, i64 0, i64 0
%21 = call i32 @getopt_long(i32 %18, i8** %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %struct.option* %20, i32* %13)
store i32 %21, i32* %9
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = load i32, i32* %9
switch i32 %24, label %29 [
i32 99, label %25
i32 116, label %27
]
25: ; preds = %23
%26 = load i8*, i8** @optarg
store i8* %26, i8** %11
br label %34
27: ; preds = %23
%28 = load i8*, i8** @optarg
store i8* %28, i8** %12
br label %34
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @usage(i8* %32)
br label %34
34: ; preds = %29, %27, %25
br label %17
35: ; preds = %17
store i32 0, i32* %14
%36 = load i32, i32* @optind
%37 = load i32, i32* %4
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %14
br label %104
40: ; preds = %35
%41 = load i32, i32* %4
%42 = load i32, i32* @optind
%43 = sub nsw i32 %41, %42
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %65
45: ; preds = %40
%46 = load i8**, i8*** %5
%47 = load i32, i32* @optind
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %45
store i32 1, i32* %14
br label %64
54: ; preds = %45
%55 = load i8**, i8*** %5
%56 = load i32, i32* @optind
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %54
store i32 2, i32* %14
br label %63
63: ; preds = %62, %54
br label %64
64: ; preds = %63, %53
br label %103
65: ; preds = %40
%66 = load i32, i32* %4
%67 = load i32, i32* @optind
%68 = sub nsw i32 %66, %67
%69 = icmp eq i32 %68, 2
br i1 %69, label %70, label %102
70: ; preds = %65
%71 = load i8**, i8*** %5
%72 = load i32, i32* @optind
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %70
store i32 3, i32* %14
%79 = load i8**, i8*** %5
%80 = load i32, i32* @optind
%81 = add nsw i32 %80, 1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8*, i8** %79, i64 %82
%84 = load i8*, i8** %83
store i8* %84, i8** %10
br label %101
85: ; preds = %70
%86 = load i8**, i8*** %5
%87 = load i32, i32* @optind
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8*, i8** %86, i64 %88
%90 = load i8*, i8** %89
%91 = call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %100
93: ; preds = %85
store i32 4, i32* %14
%94 = load i8**, i8*** %5
%95 = load i32, i32* @optind
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
store i8* %99, i8** %10
br label %100
100: ; preds = %93, %85
br label %101
101: ; preds = %100, %78
br label %102
102: ; preds = %101, %65
br label %103
103: ; preds = %102, %64
br label %104
104: ; preds = %103, %39
%105 = load i32, i32* %14
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %104
%108 = load i8**, i8*** %5
%109 = getelementptr inbounds i8*, i8** %108, i64 0
%110 = load i8*, i8** %109
%111 = call i32 @usage(i8* %110)
br label %112
112: ; preds = %107, %104
%113 = load i8*, i8** %11
%114 = load i8*, i8** %12
%115 = call %struct.chip* @chip_open(i8* %113, i8* %114)
store %struct.chip* %115, %struct.chip** %7
%116 = load %struct.chip*, %struct.chip** %7
%117 = icmp ne %struct.chip* %116, null
%118 = zext i1 %117 to i32
%119 = call i32 @assert(i32 %118)
%120 = load i32, i32* @stderr
%121 = load i8*, i8** %11
%122 = load i8*, i8** %12
%123 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %121, i8* %122)
%124 = load %struct.chip*, %struct.chip** %7
%125 = call i32 @chip_diagnose(%struct.chip* %124)
store i32 %125, i32* %8
%126 = load i32, i32* %8
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %136
128: ; preds = %112
%129 = load i32, i32* @stderr
%130 = load i8*, i8** %11
%131 = load i8*, i8** %12
%132 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %130, i8* %131)
%133 = load %struct.chip*, %struct.chip** %7
%134 = call i32 @chip_close(%struct.chip* %133)
%135 = load i32, i32* @EXIT_FAILURE
store i32 %135, i32* %3
br label %260
136: ; preds = %112
%137 = load i32, i32* %14
%138 = icmp eq i32 %137, 1
br i1 %138, label %139, label %143
139: ; preds = %136
%140 = load %struct.chip*, %struct.chip** %7
%141 = call i32 @chip_close(%struct.chip* %140)
%142 = load i32, i32* @EXIT_SUCCESS
store i32 %142, i32* %3
br label %260
143: ; preds = %136
%144 = load i32, i32* %14
%145 = icmp ne i32 %144, 2
br i1 %145, label %146, label %192
146: ; preds = %143
%147 = load i8*, i8** %10
%148 = icmp eq i8* %147, null
br i1 %148, label %149, label %157
149: ; preds = %146
%150 = load i32, i32* @stderr
%151 = load i8*, i8** %11
%152 = load i8*, i8** %12
%153 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0), i8* %151, i8* %152)
%154 = load %struct.chip*, %struct.chip** %7
%155 = call i32 @chip_close(%struct.chip* %154)
%156 = load i32, i32* @EXIT_FAILURE
store i32 %156, i32* %3
br label %260
157: ; preds = %146
%158 = load i8*, i8** %10
%159 = call i64 @strcmp(i8* %158, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%160 = icmp eq i64 %159, 0
br i1 %160, label %161, label %162
161: ; preds = %157
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8** %10
br label %162
162: ; preds = %161, %157
%163 = load i8*, i8** %10
%164 = load i32, i32* @O_RDONLY
%165 = call i32 @open(i8* %163, i32 %164)
store i32 %165, i32* %8
%166 = load i32, i32* %8
%167 = icmp slt i32 %166, 0
br i1 %167, label %168, label %177
168: ; preds = %162
%169 = load i32, i32* @stderr
%170 = load i8*, i8** %10
%171 = load i32, i32* @errno
%172 = call i8* @strerror(i32 %171)
%173 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i8* %170, i8* %172)
%174 = load %struct.chip*, %struct.chip** %7
%175 = call i32 @chip_close(%struct.chip* %174)
%176 = load i32, i32* @EXIT_FAILURE
store i32 %176, i32* %3
br label %260
177: ; preds = %162
%178 = load i32, i32* %8
%179 = call %struct.jedec* @jedec_read(i32 %178)
store %struct.jedec* %179, %struct.jedec** %6
%180 = load i32, i32* %8
%181 = call i32 @close(i32 %180)
%182 = load %struct.jedec*, %struct.jedec** %6
%183 = icmp eq %struct.jedec* %182, null
br i1 %183, label %184, label %191
184: ; preds = %177
%185 = load i32, i32* @stderr
%186 = load i8*, i8** %10
%187 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %185, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0), i8* %186)
%188 = load %struct.chip*, %struct.chip** %7
%189 = call i32 @chip_close(%struct.chip* %188)
%190 = load i32, i32* @EXIT_FAILURE
store i32 %190, i32* %3
br label %260
191: ; preds = %177
br label %192
192: ; preds = %191, %143
%193 = load i32, i32* %14
%194 = icmp eq i32 %193, 4
br i1 %194, label %195, label %196
195: ; preds = %192
br label %239
196: ; preds = %192
%197 = load i32, i32* @stderr
%198 = load i8*, i8** %11
%199 = load i8*, i8** %12
%200 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %197, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.15, i64 0, i64 0), i8* %198, i8* %199)
%201 = load %struct.chip*, %struct.chip** %7
%202 = call i32 @chip_erase(%struct.chip* %201)
store i32 %202, i32* %8
%203 = load i32, i32* %8
%204 = icmp slt i32 %203, 0
br i1 %204, label %205, label %213
205: ; preds = %196
%206 = load i32, i32* @stderr
%207 = load i8*, i8** %11
%208 = load i8*, i8** %12
%209 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %206, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i8* %207, i8* %208)
%210 = load %struct.chip*, %struct.chip** %7
%211 = call i32 @chip_close(%struct.chip* %210)
%212 = load i32, i32* @EXIT_FAILURE
store i32 %212, i32* %3
br label %260
213: ; preds = %196
%214 = load i32, i32* %14
%215 = icmp eq i32 %214, 2
br i1 %215, label %216, label %220
216: ; preds = %213
%217 = load %struct.chip*, %struct.chip** %7
%218 = call i32 @chip_close(%struct.chip* %217)
%219 = load i32, i32* @EXIT_SUCCESS
store i32 %219, i32* %3
br label %260
220: ; preds = %213
%221 = load i32, i32* @stderr
%222 = load i8*, i8** %11
%223 = load i8*, i8** %12
%224 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %221, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.17, i64 0, i64 0), i8* %222, i8* %223)
%225 = load %struct.chip*, %struct.chip** %7
%226 = load %struct.jedec*, %struct.jedec** %6
%227 = call i32 @chip_program(%struct.chip* %225, %struct.jedec* %226)
store i32 %227, i32* %8
%228 = load i32, i32* %8
%229 = icmp slt i32 %228, 0
br i1 %229, label %230, label %238
230: ; preds = %220
%231 = load i32, i32* @stderr
%232 = load i8*, i8** %11
%233 = load i8*, i8** %12
%234 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %231, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0), i8* %232, i8* %233)
%235 = load %struct.chip*, %struct.chip** %7
%236 = call i32 @chip_close(%struct.chip* %235)
%237 = load i32, i32* @EXIT_FAILURE
store i32 %237, i32* %3
br label %260
238: ; preds = %220
br label %239
239: ; preds = %238, %195
%240 = load i32, i32* @stderr
%241 = load i8*, i8** %11
%242 = load i8*, i8** %12
%243 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %240, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0), i8* %241, i8* %242)
%244 = load %struct.chip*, %struct.chip** %7
%245 = load %struct.jedec*, %struct.jedec** %6
%246 = call i32 @chip_verify(%struct.chip* %244, %struct.jedec* %245)
store i32 %246, i32* %8
%247 = load i32, i32* %8
%248 = icmp slt i32 %247, 0
br i1 %248, label %249, label %257
249: ; preds = %239
%250 = load i32, i32* @stderr
%251 = load i8*, i8** %11
%252 = load i8*, i8** %12
%253 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %250, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0), i8* %251, i8* %252)
%254 = load %struct.chip*, %struct.chip** %7
%255 = call i32 @chip_close(%struct.chip* %254)
%256 = load i32, i32* @EXIT_FAILURE
store i32 %256, i32* %3
br label %260
257: ; preds = %239
%258 = load %struct.chip*, %struct.chip** %7
%259 = call i32 @chip_close(%struct.chip* %258)
store i32 0, i32* %3
br label %260
260: ; preds = %257, %249, %230, %216, %205, %184, %168, %149, %139, %128
%261 = load i32, i32* %3
ret i32 %261
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32* }
%struct.chip = type { i32 }
%struct.jedec = type { i32 }
@.str = [5 x i8] c"chip\00"
@.str.1 = [5 x i8] c"tool\00"
@.str.2 = [5 x i8] c"help\00"
@__const.main.options = [4 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 1, i8 99, i32* null }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 1, i8 116, i32* null }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 0, i8 104, i32* null }, %struct.option zeroinitializer]
@.str.3 = [7 x i8] c"+c:t:h\00"
@optarg = global i8* null
@optind = global i32 0
@.str.4 = [6 x i8] c"check\00"
@.str.5 = [6 x i8] c"erase\00"
@.str.6 = [8 x i8] c"program\00"
@.str.7 = [7 x i8] c"verify\00"
@stderr = global i32 0
@.str.8 = [16 x i8] c"%s:%s Check...\0A\00"
@.str.9 = [34 x i8] c"%s:%s Functionality check failed\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.10 = [54 x i8] c"%s:%s No JEDEC fuse map specified for this operation\0A\00"
@.str.11 = [2 x i8] c"-\00"
@.str.12 = [11 x i8] c"/dev/stdin\00"
@O_RDONLY = global i32 0
@.str.13 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.14 = [24 x i8] c"%s: Invalid JEDEC file\0A\00"
@.str.15 = [16 x i8] c"%s:%s Erase...\0A\00"
@.str.16 = [20 x i8] c"%s:%s Erase failed\0A\00"
@.str.17 = [18 x i8] c"%s:%s Program...\0A\00"
@.str.18 = [26 x i8] c"%s:%s Programming failed\0A\00"
@.str.19 = [17 x i8] c"%s:%s Verify...\0A\00"
@.str.20 = [21 x i8] c"%s:%s Verify failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [4 x %struct.option]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [4 x %struct.option]* %4 to i8*
%7 = getelementptr inbounds [4 x %struct.option], [4 x %struct.option]* %4, i64 0, i64 0
%8 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %struct.option* %7, i32* %3)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %26
10: ; preds = %2, %21
%11 = phi i32 [ %24, %21 ], [ %8, %2 ]
%12 = phi i8* [ %23, %21 ], [ null, %2 ]
%13 = phi i8* [ %22, %21 ], [ null, %2 ]
switch i32 %11, label %18 [
i32 99, label %14
i32 116, label %16
]
14: ; preds = %10
%15 = load i8*, i8** @optarg
br label %21
16: ; preds = %10
%17 = load i8*, i8** @optarg
br label %21
18: ; preds = %10
%19 = load i8*, i8** %1
%20 = call i32 @usage(i8* %19)
br label %21
21: ; preds = %18, %16, %14
%22 = phi i8* [ %13, %18 ], [ %13, %16 ], [ %15, %14 ]
%23 = phi i8* [ %12, %18 ], [ %17, %16 ], [ %12, %14 ]
%24 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %struct.option* %7, i32* %3)
%25 = icmp sgt i32 %24, -1
br i1 %25, label %10, label %26
26: ; preds = %21, %2
%27 = phi i8* [ null, %2 ], [ %22, %21 ]
%28 = phi i8* [ null, %2 ], [ %23, %21 ]
%29 = load i32, i32* @optind
%30 = icmp eq i32 %29, %0
br i1 %30, label %73, label %31
31: ; preds = %26
%32 = sub nsw i32 %0, %29
switch i32 %32, label %70 [
i32 1, label %33
i32 2, label %39
]
33: ; preds = %31
%34 = sext i32 %29 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %73, label %63
39: ; preds = %31
%40 = sext i32 %29 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
%45 = load i32, i32* @optind
br i1 %44, label %46, label %51
46: ; preds = %39
%47 = add nsw i32 %45, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = load i8*, i8** %49
br label %73
51: ; preds = %39
%52 = sext i32 %45 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %70
57: ; preds = %51
%58 = load i32, i32* @optind
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %1, i64 %60
%62 = load i8*, i8** %61
br label %73
63: ; preds = %33
%64 = load i32, i32* @optind
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %1, i64 %65
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %73, label %70
70: ; preds = %31, %51, %63
%71 = load i8*, i8** %1
%72 = call i32 @usage(i8* %71)
br label %73
73: ; preds = %33, %26, %57, %46, %70, %63
%74 = phi i1 [ false, %70 ], [ false, %63 ], [ false, %33 ], [ false, %26 ], [ true, %57 ], [ false, %46 ]
%75 = phi i1 [ false, %70 ], [ true, %63 ], [ false, %33 ], [ false, %26 ], [ false, %57 ], [ false, %46 ]
%76 = phi i1 [ false, %70 ], [ false, %63 ], [ true, %33 ], [ true, %26 ], [ false, %57 ], [ false, %46 ]
%77 = phi i8* [ null, %70 ], [ null, %63 ], [ null, %33 ], [ null, %26 ], [ %62, %57 ], [ %50, %46 ]
%78 = call %struct.chip* @chip_open(i8* %27, i8* %28)
%79 = icmp ne %struct.chip* %78, null
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %27, i8* %28)
%84 = call i32 @chip_diagnose(%struct.chip* %78)
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %73
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %27, i8* %28)
%89 = call i32 @chip_close(%struct.chip* %78)
%90 = load i32, i32* @EXIT_FAILURE
br label %164
91: ; preds = %73
br i1 %76, label %92, label %95
92: ; preds = %91
%93 = call i32 @chip_close(%struct.chip* %78)
%94 = load i32, i32* @EXIT_SUCCESS
br label %164
95: ; preds = %91
br i1 %75, label %126, label %96
96: ; preds = %95
%97 = icmp eq i8* %77, null
br i1 %97, label %98, label %103
98: ; preds = %96
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.10, i64 0, i64 0), i8* %27, i8* %28)
%101 = call i32 @chip_close(%struct.chip* %78)
%102 = load i32, i32* @EXIT_FAILURE
br label %164
103: ; preds = %96
%104 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
%106 = select i1 %105, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %77
%107 = load i32, i32* @O_RDONLY
%108 = call i32 @open(i8* %106, i32 %107)
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %117
110: ; preds = %103
%111 = load i32, i32* @stderr
%112 = load i32, i32* @errno
%113 = call i8* @strerror(i32 %112)
%114 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i8* %106, i8* %113)
%115 = call i32 @chip_close(%struct.chip* %78)
%116 = load i32, i32* @EXIT_FAILURE
br label %164
117: ; preds = %103
%118 = call %struct.jedec* @jedec_read(i32 %108)
%119 = call i32 @close(i32 %108)
%120 = icmp eq %struct.jedec* %118, null
br i1 %120, label %121, label %126
121: ; preds = %117
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0), i8* %106)
%124 = call i32 @chip_close(%struct.chip* %78)
%125 = load i32, i32* @EXIT_FAILURE
br label %164
126: ; preds = %117, %95
%127 = phi %struct.jedec* [ %118, %117 ], [ undef, %95 ]
br i1 %74, label %152, label %128
128: ; preds = %126
%129 = load i32, i32* @stderr
%130 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.15, i64 0, i64 0), i8* %27, i8* %28)
%131 = call i32 @chip_erase(%struct.chip* %78)
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %128
%134 = load i32, i32* @stderr
%135 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i8* %27, i8* %28)
%136 = call i32 @chip_close(%struct.chip* %78)
%137 = load i32, i32* @EXIT_FAILURE
br label %164
138: ; preds = %128
br i1 %75, label %139, label %142
139: ; preds = %138
%140 = call i32 @chip_close(%struct.chip* %78)
%141 = load i32, i32* @EXIT_SUCCESS
br label %164
142: ; preds = %138
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.17, i64 0, i64 0), i8* %27, i8* %28)
%145 = call i32 @chip_program(%struct.chip* %78, %struct.jedec* %127)
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %152
147: ; preds = %142
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0), i8* %27, i8* %28)
%150 = call i32 @chip_close(%struct.chip* %78)
%151 = load i32, i32* @EXIT_FAILURE
br label %164
152: ; preds = %142, %126
%153 = load i32, i32* @stderr
%154 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0), i8* %27, i8* %28)
%155 = call i32 @chip_verify(%struct.chip* %78, %struct.jedec* %127)
%156 = icmp slt i32 %155, 0
br i1 %156, label %157, label %162
157: ; preds = %152
%158 = load i32, i32* @stderr
%159 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0), i8* %27, i8* %28)
%160 = call i32 @chip_close(%struct.chip* %78)
%161 = load i32, i32* @EXIT_FAILURE
br label %164
162: ; preds = %152
%163 = call i32 @chip_close(%struct.chip* %78)
br label %164
164: ; preds = %162, %157, %147, %139, %133, %121, %110, %98, %92, %86
%165 = phi i32 [ %90, %86 ], [ %94, %92 ], [ %102, %98 ], [ %116, %110 ], [ %125, %121 ], [ %161, %157 ], [ 0, %162 ], [ %137, %133 ], [ %141, %139 ], [ %151, %147 ]
ret i32 %165
}