#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;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int ds1307_dump(int, int, int);
int ds1307_get_sqw(int);
int ds1307_halt(int, int);
int ds1307_print_time(int);
int ds1307_sanity_check(int, int *);
int ds1307_set_hfmt(int, int);
int ds1307_set_sqw(int, int);
int ds1307_sync_time(int);
int ds1307_test_ram(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ handle_bad_opts();
int i2c_open(int);
int i2c_select(int, int);
char *optarg;
scalar_t__ opterr;
int /*<<< orphan*/ print_help(char *);
int read_int(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int file = -1;
  int res;
  if (argc < 2) {
    print_help(argv[0]);
    return 0;
  }
  int c;
  int ad = (0x68);
  opterr = 0;
  while ((c = getopt(argc, argv, "12a:b:cdDghHps:St")) != -1) {
    switch (c) {
    case '1':
    case '2': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_set_hfmt(file, '1' == c)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 'a': {
      if (file < 0) {
        fprintf(stderr,
                "ERROR: bus number not set prior to address selection.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((ad = read_int(optarg)) < 0) {
        fprintf(stderr, "ERROR: invalid slave address `%s'.\n\n", optarg);
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((ad < 0x03) || (ad > 0x7f)) {
        fprintf(stderr,
                "ERROR: invalid slave address `%s' (out of valid range of 0x03 "
                "to 0x7f).\n\n",
                optarg);
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = i2c_select(file, ad)) < 0) {
        close(file);
        return res;
      }
      fprintf(stdout, "Address set to 0x%02x\n", ad);
      break;
    }
    case 'b': {
      if (file >= 0) {
        close(file);
        file = -1;
      }
      int bn;
      if ((bn = read_int(optarg)) < 0) {
        fprintf(stderr, "ERROR: invalid bus number `%s'.\n\n", optarg);
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((file = i2c_open(bn)) < 0) {
        return file;
      }
      if ((res = i2c_select(file, ad)) < 0) {
        close(file);
        return res;
      }
      fprintf(stdout, "Address set to 0x%02x\n", ad);
      break;
    }
    case 'c': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      bool ok;
      if ((res = ds1307_sanity_check(file, &ok)) < 0) {
        close(file);
        return res;
      }
      fprintf(stdout, "Sanity check: %s\n", ok ? "PASS" : "FAIL");
      break;
    }
    case 'd':
    case 'D': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      uint8_t start = ('d' == c) ? (0x08) : 0;
      uint8_t count = ('d' == c) ? ((0x40) - (0x08)) : (0x40);
      if ((res = ds1307_dump(file, start, count)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 'g': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_get_sqw(file)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 'h':
    case 'H': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_halt(file, 'H' == c)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 'p': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_print_time(file)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 's': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      int s;
      if ((s = read_int(optarg)) < 0) {
        fprintf(stderr, "ERROR: invalid square wave setting number `%s'.\n\n",
                optarg);
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_set_sqw(file, s)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 'S': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_sync_time(file)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case 't': {
      if (file < 0) {
        fprintf(stderr, "ERROR: bus number not set prior to operation.\n\n");
        print_help(argv[0]);
        return -EINVAL;
      }
      if ((res = ds1307_test_ram(file)) < 0) {
        close(file);
        return res;
      }
      break;
    }
    case '?': {
      handle_bad_opts();
      print_help(argv[0]);
      return -EINVAL;
    }
    default: {
      fprintf(stderr, "BUG: switch fall-through on `%c'!\n", c);
      abort();
    }
    }
  }
  if (file >= 0) {
    close(file);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    125f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
movl   $0x68,-0x20(%rbp)
mov    0x2d63(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     19d0 <main+0x7b0>
mov    -0x1c(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x43,%eax
ja     19aa <main+0x78a>
mov    -0x40(%rbp),%rax
lea    0xd4d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x14(%rbp)
jge    12fc <main+0xdc>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2cd6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
mov    $0x31,%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
call   1140 <ds1307_set_hfmt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1333 <main+0x113>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    1378 <main+0x158>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2c5a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x2c79(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    13d3 <main+0x1b3>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
mov    0x2c55(%rip),%rax
mov    (%rax),%rdx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2bff(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
cmpl   $0x3,-0x20(%rbp)
jl     13e7 <main+0x1c7>
cmpl   $0x7f,-0x20(%rbp)
jle    1427 <main+0x207>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
mov    0x2c01(%rip),%rax
mov    (%rax),%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2bab(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1130 <i2c_select@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1451 <main+0x231>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x2b68(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jl     1489 <main+0x269>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x14(%rbp)
mov    0x2b68(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    14e4 <main+0x2c4>
mov    0x2b2d(%rip),%rax
mov    (%rax),%edi
mov    0x2b44(%rip),%rax
mov    (%rax),%rdx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2aee(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x24(%rbp),%edi
call   1080 <i2c_open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1503 <main+0x2e3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1130 <i2c_select@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    152d <main+0x30d>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x2a8c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xcb9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    158c <main+0x36c>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2a46(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10a0 <ds1307_sanity_check@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    15b7 <main+0x397>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x2a02(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%ecx
lea    0xc7f(%rip),%rdx
lea    0xc73(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xc53(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    162b <main+0x40b>
mov    0x29dc(%rip),%rax
mov    (%rax),%edi
lea    0xb1d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x29a7(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x1c(%rbp),%esi
mov    $0x64,%edx
xor    %eax,%eax
mov    $0x8,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x64,%edx
mov    $0x40,%eax
mov    $0x38,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1030 <ds1307_dump@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1689 <main+0x469>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    16ce <main+0x4ae>
mov    0x2939(%rip),%rax
mov    (%rax),%edi
lea    0xa7a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2904(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
call   1120 <ds1307_get_sqw@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    16f5 <main+0x4d5>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    173a <main+0x51a>
mov    0x28cd(%rip),%rax
mov    (%rax),%edi
lea    0xa0e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2898(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
mov    $0x48,%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
call   10d0 <ds1307_halt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1771 <main+0x551>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    17b6 <main+0x596>
mov    0x2851(%rip),%rax
mov    (%rax),%edi
lea    0x992(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x281c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
call   1050 <ds1307_print_time@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    17dd <main+0x5bd>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    1822 <main+0x602>
mov    0x27e5(%rip),%rax
mov    (%rax),%edi
lea    0x926(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x27b0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x27cf(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    187d <main+0x65d>
mov    0x2794(%rip),%rax
mov    (%rax),%edi
mov    0x27ab(%rip),%rax
mov    (%rax),%rdx
lea    0x9f7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2755(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1100 <ds1307_set_sqw@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    18a7 <main+0x687>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    18ec <main+0x6cc>
mov    0x271b(%rip),%rax
mov    (%rax),%edi
lea    0x85c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x26e6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
call   1070 <ds1307_sync_time@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1913 <main+0x6f3>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
cmpl   $0x0,-0x14(%rbp)
jge    1958 <main+0x738>
mov    0x26af(%rip),%rax
mov    (%rax),%edi
lea    0x7f0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x267a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    -0x14(%rbp),%edi
call   1110 <ds1307_test_ram@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    197f <main+0x75f>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
jmp    19cb <main+0x7ab>
mov    $0x0,%al
call   1060 <handle_bad_opts@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <print_help@plt>
xor    %eax,%eax
mov    0x2628(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    19e9 <main+0x7c9>
mov    0x2627(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0x8c3(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1274 <main+0x54>
cmpl   $0x0,-0x14(%rbp)
jl     19e2 <main+0x7c2>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1242 <main+0x22>
mov    (%r14),%rdi
call   10f0 <print_help@plt>
xor    %ebp,%ebp
jmp    152e <main+0x30e>
mov    %edi,%r15d
mov    0x2d84(%rip),%rax
movq   $0x0,(%rax)
mov    $0xffffffff,%ebx
mov    $0x68,%r13d
lea    0xd9b(%rip),%r12
jmp    1288 <main+0x68>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    %ebx,%edi
call   1120 <ds1307_get_sqw@plt>
cs nopw 0x0(%rax,%rax,1)
test   %eax,%eax
js     144b <main+0x22b>
mov    %r15d,%edi
mov    %r14,%rsi
lea    0xf43(%rip),%rdx
call   10e0 <getopt@plt>
lea    0x1(%rax),%ecx
cmp    $0x75,%ecx
ja     153f <main+0x31f>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
test   %ebx,%ebx
js     1459 <main+0x239>
xor    %esi,%esi
cmp    $0x31,%eax
sete   %sil
mov    %ebx,%edi
call   1140 <ds1307_set_hfmt@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1459 <main+0x239>
xor    %ecx,%ecx
xor    %esi,%esi
cmp    $0x64,%eax
setne  %cl
sete   %sil
shl    $0x3,%esi
lea    0x38(,%rcx,8),%edx
mov    %ebx,%edi
call   1030 <ds1307_dump@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1459 <main+0x239>
xor    %esi,%esi
cmp    $0x48,%eax
sete   %sil
mov    %ebx,%edi
call   10d0 <ds1307_halt@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    %ebx,%edi
call   1070 <ds1307_sync_time@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1490 <main+0x270>
mov    0x2cc6(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
test   %eax,%eax
js     14be <main+0x29e>
mov    %eax,%r13d
lea    -0x80(%r13),%eax
cmp    $0xffffff82,%eax
ja     1386 <main+0x166>
jmp    14fa <main+0x2da>
test   %ebx,%ebx
js     135e <main+0x13e>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
test   %eax,%eax
js     14a2 <main+0x282>
mov    %eax,%edi
call   1080 <i2c_open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     14da <main+0x2ba>
mov    %ebx,%edi
mov    %r13d,%esi
call   1130 <i2c_select@plt>
test   %eax,%eax
js     144b <main+0x22b>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
lea    0xf19(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1288 <main+0x68>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    %ebx,%edi
lea    0x4(%rsp),%rsi
call   10a0 <ds1307_sanity_check@plt>
test   %eax,%eax
js     144b <main+0x22b>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
cmpl   $0x0,0x4(%rsp)
lea    0xf28(%rip),%rdx
lea    0xf26(%rip),%rax
cmove  %rax,%rdx
lea    0xf04(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1288 <main+0x68>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    %ebx,%edi
call   1050 <ds1307_print_time@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    0x2bdb(%rip),%rax
mov    (%rax),%rdi
call   10c0 <read_int@plt>
test   %eax,%eax
js     14de <main+0x2be>
mov    %ebx,%edi
mov    %eax,%esi
call   1100 <ds1307_set_sqw@plt>
jmp    1280 <main+0x60>
test   %ebx,%ebx
js     1459 <main+0x239>
mov    %ebx,%edi
call   1110 <ds1307_test_ram@plt>
jmp    1280 <main+0x60>
mov    %eax,%ebp
mov    %ebx,%edi
call   1090 <close@plt>
jmp    152e <main+0x30e>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    151d <main+0x2fd>
xor    %ebp,%ebp
test   %ebx,%ebx
jns    144d <main+0x22d>
jmp    152e <main+0x30e>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <handle_bad_opts@plt>
jmp    151d <main+0x2fd>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
jmp    1469 <main+0x249>
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
mov    0x2b46(%rip),%rax
mov    (%rax),%rdx
lea    0xe1c(%rip),%rsi
jmp    1514 <main+0x2f4>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
mov    0x2b2a(%rip),%rax
mov    (%rax),%rdx
lea    0xd7a(%rip),%rsi
jmp    1514 <main+0x2f4>
mov    %ebx,%ebp
jmp    152e <main+0x30e>
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
mov    0x2b0a(%rip),%rax
mov    (%rax),%rdx
lea    0xe1e(%rip),%rsi
jmp    1514 <main+0x2f4>
mov    0x2ad7(%rip),%rax
mov    (%rax),%edi
mov    0x2aee(%rip),%rax
mov    (%rax),%rdx
lea    0xd63(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%rdi
call   10f0 <print_help@plt>
mov    0x2a9c(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a92(%rip),%rcx
mov    (%rcx),%edi
lea    0xdf9(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@opterr = global i64 0
@.str = [18 x i8] c"12a:b:cdDghHps:St\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"ERROR: bus number not set prior to operation.\0A\0A\00"
@EINVAL = global i32 0
@.str.2 = [56 x i8] c"ERROR: bus number not set prior to address selection.\0A\0A\00"
@optarg = global i8* null
@.str.3 = [37 x i8] c"ERROR: invalid slave address `%s'.\0A\0A\00"
@.str.4 = [74 x i8] c"ERROR: invalid slave address `%s' (out of valid range of 0x03 to 0x7f).\0A\0A\00"
@stdout = global i32 0
@.str.5 = [23 x i8] c"Address set to 0x%02x\0A\00"
@.str.6 = [34 x i8] c"ERROR: invalid bus number `%s'.\0A\0A\00"
@.str.7 = [18 x i8] c"Sanity check: %s\0A\00"
@.str.8 = [5 x i8] c"PASS\00"
@.str.9 = [5 x i8] c"FAIL\00"
@.str.10 = [50 x i8] c"ERROR: invalid square wave setting number `%s'.\0A\0A\00"
@.str.11 = [35 x i8] c"BUG: switch fall-through on `%c'!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @print_help(i8* %20)
store i32 0, i32* %3
br label %371
22: ; preds = %2
store i32 104, i32* %9
store i64 0, i64* @opterr
br label %23
23: ; preds = %363, %22
%24 = load i32, i32* %4
%25 = load i8**, i8*** %5
%26 = call i32 @getopt(i32 %24, i8** %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 %26, i32* %8
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %364
28: ; preds = %23
%29 = load i32, i32* %8
switch i32 %29, label %358 [
i32 49, label %30
i32 50, label %30
i32 97, label %54
i32 98, label %109
i32 99, label %148
i32 100, label %175
i32 68, label %175
i32 103, label %206
i32 104, label %227
i32 72, label %227
i32 112, label %251
i32 115, label %272
i32 83, label %308
i32 116, label %329
i32 63, label %350
]
30: ; preds = %28, %28
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @print_help(i8* %38)
%40 = load i32, i32* @EINVAL
%41 = sub nsw i32 0, %40
store i32 %41, i32* %3
br label %371
42: ; preds = %30
%43 = load i32, i32* %6
%44 = load i32, i32* %8
%45 = icmp eq i32 49, %44
%46 = zext i1 %45 to i32
%47 = call i32 @ds1307_set_hfmt(i32 %43, i32 %46)
store i32 %47, i32* %7
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* %7
store i32 %52, i32* %3
br label %371
53: ; preds = %42
br label %363
54: ; preds = %28
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @print_help(i8* %62)
%64 = load i32, i32* @EINVAL
%65 = sub nsw i32 0, %64
store i32 %65, i32* %3
br label %371
66: ; preds = %54
%67 = load i8*, i8** @optarg
%68 = call i32 @read_int(i8* %67)
store i32 %68, i32* %9
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = load i8*, i8** @optarg
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 0
%76 = load i8*, i8** %75
%77 = call i32 @print_help(i8* %76)
%78 = load i32, i32* @EINVAL
%79 = sub nsw i32 0, %78
store i32 %79, i32* %3
br label %371
80: ; preds = %66
%81 = load i32, i32* %9
%82 = icmp slt i32 %81, 3
br i1 %82, label %86, label %83
83: ; preds = %80
%84 = load i32, i32* %9
%85 = icmp sgt i32 %84, 127
br i1 %85, label %86, label %96
86: ; preds = %83, %80
%87 = load i32, i32* @stderr
%88 = load i8*, i8** @optarg
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %88)
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 0
%92 = load i8*, i8** %91
%93 = call i32 @print_help(i8* %92)
%94 = load i32, i32* @EINVAL
%95 = sub nsw i32 0, %94
store i32 %95, i32* %3
br label %371
96: ; preds = %83
%97 = load i32, i32* %6
%98 = load i32, i32* %9
%99 = call i32 @i2c_select(i32 %97, i32 %98)
store i32 %99, i32* %7
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %96
%102 = load i32, i32* %6
%103 = call i32 @close(i32 %102)
%104 = load i32, i32* %7
store i32 %104, i32* %3
br label %371
105: ; preds = %96
%106 = load i32, i32* @stdout
%107 = load i32, i32* %9
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %107)
br label %363
109: ; preds = %28
%110 = load i32, i32* %6
%111 = icmp sge i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %109
%113 = load i32, i32* %6
%114 = call i32 @close(i32 %113)
store i32 -1, i32* %6
br label %115
115: ; preds = %112, %109
%116 = load i8*, i8** @optarg
%117 = call i32 @read_int(i8* %116)
store i32 %117, i32* %10
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %129
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = load i8*, i8** @optarg
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %121)
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 0
%125 = load i8*, i8** %124
%126 = call i32 @print_help(i8* %125)
%127 = load i32, i32* @EINVAL
%128 = sub nsw i32 0, %127
store i32 %128, i32* %3
br label %371
129: ; preds = %115
%130 = load i32, i32* %10
%131 = call i32 @i2c_open(i32 %130)
store i32 %131, i32* %6
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %129
%134 = load i32, i32* %6
store i32 %134, i32* %3
br label %371
135: ; preds = %129
%136 = load i32, i32* %6
%137 = load i32, i32* %9
%138 = call i32 @i2c_select(i32 %136, i32 %137)
store i32 %138, i32* %7
%139 = icmp slt i32 %138, 0
br i1 %139, label %140, label %144
140: ; preds = %135
%141 = load i32, i32* %6
%142 = call i32 @close(i32 %141)
%143 = load i32, i32* %7
store i32 %143, i32* %3
br label %371
144: ; preds = %135
%145 = load i32, i32* @stdout
%146 = load i32, i32* %9
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %146)
br label %363
148: ; preds = %28
%149 = load i32, i32* %6
%150 = icmp slt i32 %149, 0
br i1 %150, label %151, label %160
151: ; preds = %148
%152 = load i32, i32* @stderr
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 0
%156 = load i8*, i8** %155
%157 = call i32 @print_help(i8* %156)
%158 = load i32, i32* @EINVAL
%159 = sub nsw i32 0, %158
store i32 %159, i32* %3
br label %371
160: ; preds = %148
%161 = load i32, i32* %6
%162 = call i32 @ds1307_sanity_check(i32 %161, i32* %11)
store i32 %162, i32* %7
%163 = icmp slt i32 %162, 0
br i1 %163, label %164, label %168
164: ; preds = %160
%165 = load i32, i32* %6
%166 = call i32 @close(i32 %165)
%167 = load i32, i32* %7
store i32 %167, i32* %3
br label %371
168: ; preds = %160
%169 = load i32, i32* @stdout
%170 = load i32, i32* %11
%171 = icmp ne i32 %170, 0
%172 = zext i1 %171 to i64
%173 = select i1 %171, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0)
%174 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %173)
br label %363
175: ; preds = %28, %28
%176 = load i32, i32* %6
%177 = icmp slt i32 %176, 0
br i1 %177, label %178, label %187
178: ; preds = %175
%179 = load i32, i32* @stderr
%180 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%181 = load i8**, i8*** %5
%182 = getelementptr inbounds i8*, i8** %181, i64 0
%183 = load i8*, i8** %182
%184 = call i32 @print_help(i8* %183)
%185 = load i32, i32* @EINVAL
%186 = sub nsw i32 0, %185
store i32 %186, i32* %3
br label %371
187: ; preds = %175
%188 = load i32, i32* %8
%189 = icmp eq i32 100, %188
%190 = zext i1 %189 to i64
%191 = select i1 %189, i32 8, i32 0
store i32 %191, i32* %12
%192 = load i32, i32* %8
%193 = icmp eq i32 100, %192
%194 = zext i1 %193 to i64
%195 = select i1 %193, i32 56, i32 64
store i32 %195, i32* %13
%196 = load i32, i32* %6
%197 = load i32, i32* %12
%198 = load i32, i32* %13
%199 = call i32 @ds1307_dump(i32 %196, i32 %197, i32 %198)
store i32 %199, i32* %7
%200 = icmp slt i32 %199, 0
br i1 %200, label %201, label %205
201: ; preds = %187
%202 = load i32, i32* %6
%203 = call i32 @close(i32 %202)
%204 = load i32, i32* %7
store i32 %204, i32* %3
br label %371
205: ; preds = %187
br label %363
206: ; preds = %28
%207 = load i32, i32* %6
%208 = icmp slt i32 %207, 0
br i1 %208, label %209, label %218
209: ; preds = %206
%210 = load i32, i32* @stderr
%211 = call i32 (i32, i8*, ...) @fprintf(i32 %210, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%212 = load i8**, i8*** %5
%213 = getelementptr inbounds i8*, i8** %212, i64 0
%214 = load i8*, i8** %213
%215 = call i32 @print_help(i8* %214)
%216 = load i32, i32* @EINVAL
%217 = sub nsw i32 0, %216
store i32 %217, i32* %3
br label %371
218: ; preds = %206
%219 = load i32, i32* %6
%220 = call i32 @ds1307_get_sqw(i32 %219)
store i32 %220, i32* %7
%221 = icmp slt i32 %220, 0
br i1 %221, label %222, label %226
222: ; preds = %218
%223 = load i32, i32* %6
%224 = call i32 @close(i32 %223)
%225 = load i32, i32* %7
store i32 %225, i32* %3
br label %371
226: ; preds = %218
br label %363
227: ; preds = %28, %28
%228 = load i32, i32* %6
%229 = icmp slt i32 %228, 0
br i1 %229, label %230, label %239
230: ; preds = %227
%231 = load i32, i32* @stderr
%232 = call i32 (i32, i8*, ...) @fprintf(i32 %231, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%233 = load i8**, i8*** %5
%234 = getelementptr inbounds i8*, i8** %233, i64 0
%235 = load i8*, i8** %234
%236 = call i32 @print_help(i8* %235)
%237 = load i32, i32* @EINVAL
%238 = sub nsw i32 0, %237
store i32 %238, i32* %3
br label %371
239: ; preds = %227
%240 = load i32, i32* %6
%241 = load i32, i32* %8
%242 = icmp eq i32 72, %241
%243 = zext i1 %242 to i32
%244 = call i32 @ds1307_halt(i32 %240, i32 %243)
store i32 %244, i32* %7
%245 = icmp slt i32 %244, 0
br i1 %245, label %246, label %250
246: ; preds = %239
%247 = load i32, i32* %6
%248 = call i32 @close(i32 %247)
%249 = load i32, i32* %7
store i32 %249, i32* %3
br label %371
250: ; preds = %239
br label %363
251: ; preds = %28
%252 = load i32, i32* %6
%253 = icmp slt i32 %252, 0
br i1 %253, label %254, label %263
254: ; preds = %251
%255 = load i32, i32* @stderr
%256 = call i32 (i32, i8*, ...) @fprintf(i32 %255, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%257 = load i8**, i8*** %5
%258 = getelementptr inbounds i8*, i8** %257, i64 0
%259 = load i8*, i8** %258
%260 = call i32 @print_help(i8* %259)
%261 = load i32, i32* @EINVAL
%262 = sub nsw i32 0, %261
store i32 %262, i32* %3
br label %371
263: ; preds = %251
%264 = load i32, i32* %6
%265 = call i32 @ds1307_print_time(i32 %264)
store i32 %265, i32* %7
%266 = icmp slt i32 %265, 0
br i1 %266, label %267, label %271
267: ; preds = %263
%268 = load i32, i32* %6
%269 = call i32 @close(i32 %268)
%270 = load i32, i32* %7
store i32 %270, i32* %3
br label %371
271: ; preds = %263
br label %363
272: ; preds = %28
%273 = load i32, i32* %6
%274 = icmp slt i32 %273, 0
br i1 %274, label %275, label %284
275: ; preds = %272
%276 = load i32, i32* @stderr
%277 = call i32 (i32, i8*, ...) @fprintf(i32 %276, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%278 = load i8**, i8*** %5
%279 = getelementptr inbounds i8*, i8** %278, i64 0
%280 = load i8*, i8** %279
%281 = call i32 @print_help(i8* %280)
%282 = load i32, i32* @EINVAL
%283 = sub nsw i32 0, %282
store i32 %283, i32* %3
br label %371
284: ; preds = %272
%285 = load i8*, i8** @optarg
%286 = call i32 @read_int(i8* %285)
store i32 %286, i32* %14
%287 = icmp slt i32 %286, 0
br i1 %287, label %288, label %298
288: ; preds = %284
%289 = load i32, i32* @stderr
%290 = load i8*, i8** @optarg
%291 = call i32 (i32, i8*, ...) @fprintf(i32 %289, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %290)
%292 = load i8**, i8*** %5
%293 = getelementptr inbounds i8*, i8** %292, i64 0
%294 = load i8*, i8** %293
%295 = call i32 @print_help(i8* %294)
%296 = load i32, i32* @EINVAL
%297 = sub nsw i32 0, %296
store i32 %297, i32* %3
br label %371
298: ; preds = %284
%299 = load i32, i32* %6
%300 = load i32, i32* %14
%301 = call i32 @ds1307_set_sqw(i32 %299, i32 %300)
store i32 %301, i32* %7
%302 = icmp slt i32 %301, 0
br i1 %302, label %303, label %307
303: ; preds = %298
%304 = load i32, i32* %6
%305 = call i32 @close(i32 %304)
%306 = load i32, i32* %7
store i32 %306, i32* %3
br label %371
307: ; preds = %298
br label %363
308: ; preds = %28
%309 = load i32, i32* %6
%310 = icmp slt i32 %309, 0
br i1 %310, label %311, label %320
311: ; preds = %308
%312 = load i32, i32* @stderr
%313 = call i32 (i32, i8*, ...) @fprintf(i32 %312, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%314 = load i8**, i8*** %5
%315 = getelementptr inbounds i8*, i8** %314, i64 0
%316 = load i8*, i8** %315
%317 = call i32 @print_help(i8* %316)
%318 = load i32, i32* @EINVAL
%319 = sub nsw i32 0, %318
store i32 %319, i32* %3
br label %371
320: ; preds = %308
%321 = load i32, i32* %6
%322 = call i32 @ds1307_sync_time(i32 %321)
store i32 %322, i32* %7
%323 = icmp slt i32 %322, 0
br i1 %323, label %324, label %328
324: ; preds = %320
%325 = load i32, i32* %6
%326 = call i32 @close(i32 %325)
%327 = load i32, i32* %7
store i32 %327, i32* %3
br label %371
328: ; preds = %320
br label %363
329: ; preds = %28
%330 = load i32, i32* %6
%331 = icmp slt i32 %330, 0
br i1 %331, label %332, label %341
332: ; preds = %329
%333 = load i32, i32* @stderr
%334 = call i32 (i32, i8*, ...) @fprintf(i32 %333, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%335 = load i8**, i8*** %5
%336 = getelementptr inbounds i8*, i8** %335, i64 0
%337 = load i8*, i8** %336
%338 = call i32 @print_help(i8* %337)
%339 = load i32, i32* @EINVAL
%340 = sub nsw i32 0, %339
store i32 %340, i32* %3
br label %371
341: ; preds = %329
%342 = load i32, i32* %6
%343 = call i32 @ds1307_test_ram(i32 %342)
store i32 %343, i32* %7
%344 = icmp slt i32 %343, 0
br i1 %344, label %345, label %349
345: ; preds = %341
%346 = load i32, i32* %6
%347 = call i32 @close(i32 %346)
%348 = load i32, i32* %7
store i32 %348, i32* %3
br label %371
349: ; preds = %341
br label %363
350: ; preds = %28
%351 = call i32 (...) @handle_bad_opts()
%352 = load i8**, i8*** %5
%353 = getelementptr inbounds i8*, i8** %352, i64 0
%354 = load i8*, i8** %353
%355 = call i32 @print_help(i8* %354)
%356 = load i32, i32* @EINVAL
%357 = sub nsw i32 0, %356
store i32 %357, i32* %3
br label %371
358: ; preds = %28
%359 = load i32, i32* @stderr
%360 = load i32, i32* %8
%361 = call i32 (i32, i8*, ...) @fprintf(i32 %359, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %360)
%362 = call i32 (...) @abort()
unreachable
363: ; preds = %349, %328, %307, %271, %250, %226, %205, %168, %144, %105, %53
br label %23
364: ; preds = %23
%365 = load i32, i32* %6
%366 = icmp sge i32 %365, 0
br i1 %366, label %367, label %370
367: ; preds = %364
%368 = load i32, i32* %6
%369 = call i32 @close(i32 %368)
br label %370
370: ; preds = %367, %364
store i32 0, i32* %3
br label %371
371: ; preds = %370, %350, %345, %332, %324, %311, %303, %288, %275, %267, %254, %246, %230, %222, %209, %201, %178, %164, %151, %140, %133, %119, %101, %86, %70, %57, %49, %33, %17
%372 = load i32, i32* %3
ret i32 %372
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [18 x i8] c"12a:b:cdDghHps:St\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"ERROR: bus number not set prior to operation.\0A\0A\00"
@EINVAL = global i32 0
@.str.2 = [56 x i8] c"ERROR: bus number not set prior to address selection.\0A\0A\00"
@optarg = global i8* null
@.str.3 = [37 x i8] c"ERROR: invalid slave address `%s'.\0A\0A\00"
@.str.4 = [74 x i8] c"ERROR: invalid slave address `%s' (out of valid range of 0x03 to 0x7f).\0A\0A\00"
@stdout = global i32 0
@.str.5 = [23 x i8] c"Address set to 0x%02x\0A\00"
@.str.6 = [34 x i8] c"ERROR: invalid bus number `%s'.\0A\0A\00"
@.str.7 = [18 x i8] c"Sanity check: %s\0A\00"
@.str.8 = [5 x i8] c"PASS\00"
@.str.9 = [5 x i8] c"FAIL\00"
@.str.10 = [50 x i8] c"ERROR: invalid square wave setting number `%s'.\0A\0A\00"
@.str.11 = [35 x i8] c"BUG: switch fall-through on `%c'!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @print_help(i8* %6)
br label %249
8: ; preds = %2
store i64 0, i64* @opterr
%9 = bitcast i32* %3 to i8*
br label %10
10: ; preds = %202, %8
%11 = phi i32 [ 104, %8 ], [ %203, %202 ]
%12 = phi i32 [ -1, %8 ], [ %204, %202 ]
%13 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %241 [
i32 -1, label %245
i32 49, label %14
i32 50, label %14
i32 97, label %30
i32 98, label %70
i32 99, label %97
i32 100, label %117
i32 68, label %117
i32 103, label %134
i32 104, label %148
i32 72, label %148
i32 112, label %164
i32 115, label %178
i32 83, label %207
i32 116, label %221
i32 63, label %235
]
14: ; preds = %10, %10
%15 = icmp slt i32 %12, 0
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %1
%20 = call i32 @print_help(i8* %19)
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
br label %249
23: ; preds = %14
%24 = icmp eq i32 %13, 49
%25 = zext i1 %24 to i32
%26 = call i32 @ds1307_set_hfmt(i32 %12, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %202
28: ; preds = %23
%29 = call i32 @close(i32 %12)
br label %249
30: ; preds = %10
%31 = icmp slt i32 %12, 0
br i1 %31, label %32, label %39
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%35 = load i8*, i8** %1
%36 = call i32 @print_help(i8* %35)
%37 = load i32, i32* @EINVAL
%38 = sub nsw i32 0, %37
br label %249
39: ; preds = %30
%40 = load i8*, i8** @optarg
%41 = call i32 @read_int(i8* %40)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = load i8*, i8** @optarg
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %1
%48 = call i32 @print_help(i8* %47)
%49 = load i32, i32* @EINVAL
%50 = sub nsw i32 0, %49
br label %249
51: ; preds = %39
%52 = add nsw i32 %41, -128
%53 = icmp ult i32 %52, -125
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = load i8*, i8** @optarg
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = load i8*, i8** %1
%59 = call i32 @print_help(i8* %58)
%60 = load i32, i32* @EINVAL
%61 = sub nsw i32 0, %60
br label %249
62: ; preds = %51
%63 = call i32 @i2c_select(i32 %12, i32 %41)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @close(i32 %12)
br label %249
67: ; preds = %62
%68 = load i32, i32* @stdout
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %202
70: ; preds = %10
%71 = icmp sgt i32 %12, -1
br i1 %71, label %72, label %74
72: ; preds = %70
%73 = call i32 @close(i32 %12)
br label %74
74: ; preds = %72, %70
%75 = load i8*, i8** @optarg
%76 = call i32 @read_int(i8* %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = load i8*, i8** @optarg
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %80)
%82 = load i8*, i8** %1
%83 = call i32 @print_help(i8* %82)
%84 = load i32, i32* @EINVAL
%85 = sub nsw i32 0, %84
br label %249
86: ; preds = %74
%87 = call i32 @i2c_open(i32 %76)
%88 = icmp slt i32 %87, 0
br i1 %88, label %249, label %89
89: ; preds = %86
%90 = call i32 @i2c_select(i32 %87, i32 %11)
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @close(i32 %87)
br label %249
94: ; preds = %89
%95 = load i32, i32* @stdout
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %11)
br label %202
97: ; preds = %10
%98 = icmp slt i32 %12, 0
br i1 %98, label %99, label %106
99: ; preds = %97
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%102 = load i8*, i8** %1
%103 = call i32 @print_help(i8* %102)
%104 = load i32, i32* @EINVAL
%105 = sub nsw i32 0, %104
br label %249
106: ; preds = %97
%107 = call i32 @ds1307_sanity_check(i32 %12, i32* %3)
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %106
%110 = call i32 @close(i32 %12)
br label %249
111: ; preds = %106
%112 = load i32, i32* @stdout
%113 = load i32, i32* %3
%114 = icmp eq i32 %113, 0
%115 = select i1 %114, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %115)
br label %202
117: ; preds = %10, %10
%118 = icmp slt i32 %12, 0
br i1 %118, label %119, label %126
119: ; preds = %117
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%122 = load i8*, i8** %1
%123 = call i32 @print_help(i8* %122)
%124 = load i32, i32* @EINVAL
%125 = sub nsw i32 0, %124
br label %249
126: ; preds = %117
%127 = icmp eq i32 %13, 100
%128 = select i1 %127, i32 8, i32 0
%129 = select i1 %127, i32 56, i32 64
%130 = call i32 @ds1307_dump(i32 %12, i32 %128, i32 %129)
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %202
132: ; preds = %126
%133 = call i32 @close(i32 %12)
br label %249
134: ; preds = %10
%135 = icmp slt i32 %12, 0
br i1 %135, label %136, label %143
136: ; preds = %134
%137 = load i32, i32* @stderr
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%139 = load i8*, i8** %1
%140 = call i32 @print_help(i8* %139)
%141 = load i32, i32* @EINVAL
%142 = sub nsw i32 0, %141
br label %249
143: ; preds = %134
%144 = call i32 @ds1307_get_sqw(i32 %12)
%145 = icmp slt i32 %144, 0
br i1 %145, label %146, label %202
146: ; preds = %143
%147 = call i32 @close(i32 %12)
br label %249
148: ; preds = %10, %10
%149 = icmp slt i32 %12, 0
br i1 %149, label %150, label %157
150: ; preds = %148
%151 = load i32, i32* @stderr
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%153 = load i8*, i8** %1
%154 = call i32 @print_help(i8* %153)
%155 = load i32, i32* @EINVAL
%156 = sub nsw i32 0, %155
br label %249
157: ; preds = %148
%158 = icmp eq i32 %13, 72
%159 = zext i1 %158 to i32
%160 = call i32 @ds1307_halt(i32 %12, i32 %159)
%161 = icmp slt i32 %160, 0
br i1 %161, label %162, label %202
162: ; preds = %157
%163 = call i32 @close(i32 %12)
br label %249
164: ; preds = %10
%165 = icmp slt i32 %12, 0
br i1 %165, label %166, label %173
166: ; preds = %164
%167 = load i32, i32* @stderr
%168 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%169 = load i8*, i8** %1
%170 = call i32 @print_help(i8* %169)
%171 = load i32, i32* @EINVAL
%172 = sub nsw i32 0, %171
br label %249
173: ; preds = %164
%174 = call i32 @ds1307_print_time(i32 %12)
%175 = icmp slt i32 %174, 0
br i1 %175, label %176, label %202
176: ; preds = %173
%177 = call i32 @close(i32 %12)
br label %249
178: ; preds = %10
%179 = icmp slt i32 %12, 0
br i1 %179, label %180, label %187
180: ; preds = %178
%181 = load i32, i32* @stderr
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %181, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%183 = load i8*, i8** %1
%184 = call i32 @print_help(i8* %183)
%185 = load i32, i32* @EINVAL
%186 = sub nsw i32 0, %185
br label %249
187: ; preds = %178
%188 = load i8*, i8** @optarg
%189 = call i32 @read_int(i8* %188)
%190 = icmp slt i32 %189, 0
br i1 %190, label %191, label %199
191: ; preds = %187
%192 = load i32, i32* @stderr
%193 = load i8*, i8** @optarg
%194 = call i32 (i32, i8*, ...) @fprintf(i32 %192, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %193)
%195 = load i8*, i8** %1
%196 = call i32 @print_help(i8* %195)
%197 = load i32, i32* @EINVAL
%198 = sub nsw i32 0, %197
br label %249
199: ; preds = %187
%200 = call i32 @ds1307_set_sqw(i32 %12, i32 %189)
%201 = icmp slt i32 %200, 0
br i1 %201, label %205, label %202
202: ; preds = %199, %126, %111, %94, %230, %216, %173, %157, %143, %23, %67
%203 = phi i32 [ %11, %230 ], [ %11, %216 ], [ %11, %173 ], [ %11, %157 ], [ %11, %143 ], [ %11, %111 ], [ %11, %94 ], [ %41, %67 ], [ %11, %23 ], [ %11, %126 ], [ %11, %199 ]
%204 = phi i32 [ %12, %230 ], [ %12, %216 ], [ %12, %173 ], [ %12, %157 ], [ %12, %143 ], [ %12, %111 ], [ %87, %94 ], [ %12, %67 ], [ %12, %23 ], [ %12, %126 ], [ %12, %199 ]
br label %10
205: ; preds = %199
%206 = call i32 @close(i32 %12)
br label %249
207: ; preds = %10
%208 = icmp slt i32 %12, 0
br i1 %208, label %209, label %216
209: ; preds = %207
%210 = load i32, i32* @stderr
%211 = call i32 (i32, i8*, ...) @fprintf(i32 %210, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%212 = load i8*, i8** %1
%213 = call i32 @print_help(i8* %212)
%214 = load i32, i32* @EINVAL
%215 = sub nsw i32 0, %214
br label %249
216: ; preds = %207
%217 = call i32 @ds1307_sync_time(i32 %12)
%218 = icmp slt i32 %217, 0
br i1 %218, label %219, label %202
219: ; preds = %216
%220 = call i32 @close(i32 %12)
br label %249
221: ; preds = %10
%222 = icmp slt i32 %12, 0
br i1 %222, label %223, label %230
223: ; preds = %221
%224 = load i32, i32* @stderr
%225 = call i32 (i32, i8*, ...) @fprintf(i32 %224, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%226 = load i8*, i8** %1
%227 = call i32 @print_help(i8* %226)
%228 = load i32, i32* @EINVAL
%229 = sub nsw i32 0, %228
br label %249
230: ; preds = %221
%231 = call i32 @ds1307_test_ram(i32 %12)
%232 = icmp slt i32 %231, 0
br i1 %232, label %233, label %202
233: ; preds = %230
%234 = call i32 @close(i32 %12)
br label %249
235: ; preds = %10
%236 = call i32 (...) @handle_bad_opts()
%237 = load i8*, i8** %1
%238 = call i32 @print_help(i8* %237)
%239 = load i32, i32* @EINVAL
%240 = sub nsw i32 0, %239
br label %249
241: ; preds = %10
%242 = load i32, i32* @stderr
%243 = call i32 (i32, i8*, ...) @fprintf(i32 %242, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %13)
%244 = call i32 (...) @abort()
unreachable
245: ; preds = %10
%246 = icmp sgt i32 %12, -1
br i1 %246, label %247, label %249
247: ; preds = %245
%248 = call i32 @close(i32 %12)
br label %249
249: ; preds = %86, %191, %205, %78, %92, %132, %109, %16, %28, %32, %43, %54, %65, %99, %119, %136, %146, %150, %162, %166, %176, %180, %209, %219, %223, %233, %235, %247, %245, %5
%250 = phi i32 [ 0, %5 ], [ %240, %235 ], [ %229, %223 ], [ %231, %233 ], [ %215, %209 ], [ %217, %219 ], [ %186, %180 ], [ %172, %166 ], [ %174, %176 ], [ %156, %150 ], [ %160, %162 ], [ %142, %136 ], [ %144, %146 ], [ %125, %119 ], [ %105, %99 ], [ %38, %32 ], [ %50, %43 ], [ %61, %54 ], [ %63, %65 ], [ %22, %16 ], [ %26, %28 ], [ 0, %247 ], [ 0, %245 ], [ %107, %109 ], [ %130, %132 ], [ %85, %78 ], [ %90, %92 ], [ %198, %191 ], [ %200, %205 ], [ %87, %86 ]
ret i32 %250
}