#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 termios {
  int dummy;
};

/* Variables and functions */
int B110;
int B1200;
int B150;
int B19200;
int B200;
int B2400;
int B300;
int B38400;
int B4800;
int B50;
int B600;
int B75;
int B9600;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCSANOW;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int p;
  int fd;
  char *device;
  struct termios tio;
  int period = 60;
  int baud = 50;
  int is_daemon = 1;
  int verbose = 0;
  int pid;
  while ((p = getopt(argc, argv, "dvp:b:")) != -1) {
    switch (p) {
    case 'p':
      period = atoi(optarg);
      break;
    case 'b':
      baud = atoi(optarg);
      break;
    case 'd':
      is_daemon = 0;
      break;
    case 'v':
      ++verbose;
      break;
    case '?':
    case ':':
      fprintf(stderr, "usage: fpacwdog [-v] [-d] [-b baudrate] [-p seconds] "
                      "serial_device\n");
      return 1;
    }
  }
  if (optind == argc) {
    fprintf(
        stderr,
        "usage: fpacwdog [-v] [-d] [-b baudrate] [-p seconds] serial_device\n");
    return 1;
  }
  device = argv[optind];
  if (verbose) {
    printf("Period : %d second(s)\n", period);
    printf("Baudrate %d\n", baud);
  }
  switch (baud) {
  case 50:
    baud = B50;
    break;
  case 75:
    baud = B75;
    break;
  case 110:
    baud = B110;
    break;
  case 150:
    baud = B150;
    break;
  case 200:
    baud = B200;
    break;
  case 300:
    baud = B300;
    break;
  case 600:
    baud = B600;
    break;
  case 1200:
    baud = B1200;
    break;
  case 2400:
    baud = B2400;
    break;
  case 4800:
    baud = B4800;
    break;
  case 9600:
    baud = B9600;
    break;
  case 19200:
    baud = B19200;
    break;
  case 38400:
    baud = B38400;
    break;
  default:
    fprintf(stderr, "Invalid baudrate %d\n", baud);
    return 1;
  }
  fd = open(device, O_RDWR);
  if (fd == -1) {
    fprintf(stderr, "Cannot open serial device %s\n", device);
    return 1;
  }
  if (tcgetattr(fd, &tio) == 0) {
    cfsetospeed(&tio, baud);
    tcsetattr(fd, TCSANOW, &tio);
  }
  if (is_daemon) {
    pid = fork();
    if (pid == -1) {
      fprintf(stderr, "fpacwdog cannot become daemon\n");
      exit(1);
    }
    if (pid > 0) {
      if (verbose)
        printf("Background mode [%d]\n", pid);
      return 0;
    }
  } else {
    if (verbose)
      printf("Foreground mode\n");
  }
  for (;;) {
    if (verbose)
      printf("Sending CR\n");
    write(fd, "\r", 1);
    sleep(period);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3c,-0x2c(%rbp)
movl   $0x32,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe00(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12e8 <main+0x128>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x3a,%eax
je     12c0 <main+0x100>
jmp    1225 <main+0x65>
mov    -0x40(%rbp),%eax
sub    $0x3f,%eax
je     12c0 <main+0x100>
jmp    1236 <main+0x76>
mov    -0x40(%rbp),%eax
sub    $0x62,%eax
je     1290 <main+0xd0>
jmp    1247 <main+0x87>
mov    -0x40(%rbp),%eax
sub    $0x64,%eax
je     12a6 <main+0xe6>
jmp    1258 <main+0x98>
mov    -0x40(%rbp),%eax
sub    $0x70,%eax
je     127a <main+0xba>
jmp    1269 <main+0xa9>
mov    -0x40(%rbp),%eax
sub    $0x76,%eax
je     12b2 <main+0xf2>
jmp    12e3 <main+0x123>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    12e3 <main+0x123>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    12e3 <main+0x123>
movl   $0x0,-0x34(%rbp)
jmp    12e3 <main+0x123>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12e3 <main+0x123>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a3 <main+0x4e3>
jmp    11f2 <main+0x32>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    131d <main+0x15d>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a3 <main+0x4e3>
mov    -0x10(%rbp),%rax
mov    0x2c78(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     135f <main+0x19f>
mov    -0x2c(%rbp),%esi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x32,%eax
je     1453 <main+0x293>
jmp    1373 <main+0x1b3>
mov    -0x44(%rbp),%eax
sub    $0x4b,%eax
je     1464 <main+0x2a4>
jmp    1384 <main+0x1c4>
mov    -0x44(%rbp),%eax
sub    $0x6e,%eax
je     1475 <main+0x2b5>
jmp    1395 <main+0x1d5>
mov    -0x44(%rbp),%eax
sub    $0x96,%eax
je     1486 <main+0x2c6>
jmp    13a8 <main+0x1e8>
mov    -0x44(%rbp),%eax
sub    $0xc8,%eax
je     1497 <main+0x2d7>
jmp    13bb <main+0x1fb>
mov    -0x44(%rbp),%eax
sub    $0x12c,%eax
je     14a8 <main+0x2e8>
jmp    13ce <main+0x20e>
mov    -0x44(%rbp),%eax
sub    $0x258,%eax
je     14b9 <main+0x2f9>
jmp    13e1 <main+0x221>
mov    -0x44(%rbp),%eax
sub    $0x4b0,%eax
je     14ca <main+0x30a>
jmp    13f4 <main+0x234>
mov    -0x44(%rbp),%eax
sub    $0x960,%eax
je     14db <main+0x31b>
jmp    1407 <main+0x247>
mov    -0x44(%rbp),%eax
sub    $0x12c0,%eax
je     14ec <main+0x32c>
jmp    141a <main+0x25a>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     14fd <main+0x33d>
jmp    142d <main+0x26d>
mov    -0x44(%rbp),%eax
sub    $0x4b00,%eax
je     150e <main+0x34e>
jmp    1440 <main+0x280>
mov    -0x44(%rbp),%eax
sub    $0x9600,%eax
je     151f <main+0x35f>
jmp    1530 <main+0x370>
mov    0x2b36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2b5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2b54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2adb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2aea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2ae9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2af8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2a8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2a8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2abd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2aa4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2ad3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2a2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1556 <main+0x396>
mov    0x2a41(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xb2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a3 <main+0x4e3>
mov    -0x20(%rbp),%rdi
mov    0x2a77(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    159c <main+0x3dc>
mov    0x29fc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xafb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16a3 <main+0x4e3>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <tcgetattr@plt>
cmp    $0x0,%rax
jne    15d3 <main+0x413>
mov    -0x30(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    -0x18(%rbp),%edi
mov    0x29f8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmpl   $0x0,-0x34(%rbp)
je     1648 <main+0x488>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1612 <main+0x452>
mov    0x2980(%rip),%rax
mov    (%rax),%edi
lea    0xaa1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    1643 <main+0x483>
cmpl   $0x0,-0x38(%rbp)
je     1637 <main+0x477>
mov    -0x3c(%rbp),%esi
lea    0xa91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    16a3 <main+0x4e3>
jmp    1665 <main+0x4a5>
cmpl   $0x0,-0x38(%rbp)
je     1660 <main+0x4a0>
lea    0xa7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1665 <main+0x4a5>
jmp    166a <main+0x4aa>
cmpl   $0x0,-0x38(%rbp)
je     1682 <main+0x4c2>
lea    0xa6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xa68(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x2c(%rbp),%edi
call   10d0 <sleep@plt>
jmp    166a <main+0x4aa>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %r13d,%r13d
movl   $0x1,0xc(%rsp)
movl   $0x32,0x8(%rsp)
mov    $0x3c,%ebx
lea    0xe52(%rip),%r12
lea    0xdf7(%rip),%r15
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
cmp    $0x61,%eax
jle    1250 <main+0x80>
add    $0xffffff9e,%eax
cmp    $0x14,%eax
ja     1210 <main+0x40>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10c0 <atoi@plt>
mov    %eax,0x8(%rsp)
jmp    1210 <main+0x40>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1283 <main+0xb3>
cmp    $0x3a,%eax
je     1291 <main+0xc1>
cmp    $0x3f,%eax
jne    1210 <main+0x40>
jmp    1291 <main+0xc1>
movl   $0x0,0xc(%rsp)
jmp    1210 <main+0x40>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10c0 <atoi@plt>
mov    %eax,%ebx
jmp    1210 <main+0x40>
add    $0x1,%r13d
jmp    1210 <main+0x40>
mov    0x2d16(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jne    12be <main+0xee>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14,%rax,8),%r14
test   %r13d,%r13d
je     12ed <main+0x11d>
lea    0xdd1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd8(%rip),%rdi
mov    0x8(%rsp),%ebp
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12f1 <main+0x121>
mov    0x8(%rsp),%ebp
mov    0x2c98(%rip),%rax
cmp    $0x257,%ebp
jle    1338 <main+0x168>
cmp    $0x12bf,%ebp
jle    1367 <main+0x197>
cmp    $0x4aff,%ebp
jg     13b1 <main+0x1e1>
cmp    $0x12c0,%ebp
je     13ce <main+0x1fe>
cmp    $0x2580,%ebp
jne    14ca <main+0x2fa>
mov    0x2c75(%rip),%rax
jmp    140b <main+0x23b>
cmp    $0x95,%ebp
jg     138c <main+0x1bc>
cmp    $0x32,%ebp
je     140b <main+0x23b>
cmp    $0x4b,%ebp
je     13d7 <main+0x207>
cmp    $0x6e,%ebp
jne    14ca <main+0x2fa>
mov    0x2c6e(%rip),%rax
jmp    140b <main+0x23b>
cmp    $0x258,%ebp
je     13e0 <main+0x210>
cmp    $0x4b0,%ebp
je     13e9 <main+0x219>
cmp    $0x960,%ebp
jne    14ca <main+0x2fa>
mov    0x2be6(%rip),%rax
jmp    140b <main+0x23b>
cmp    $0x96,%ebp
je     13f2 <main+0x222>
cmp    $0xc8,%ebp
je     13fb <main+0x22b>
cmp    $0x12c,%ebp
jne    14ca <main+0x2fa>
mov    0x2be9(%rip),%rax
jmp    140b <main+0x23b>
cmp    $0x4b00,%ebp
je     1404 <main+0x234>
cmp    $0x9600,%ebp
jne    14ca <main+0x2fa>
mov    0x2b84(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2bdb(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2bea(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2bd1(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2b70(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2b6f(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2b86(%rip),%rax
jmp    140b <main+0x23b>
mov    0x2bdd(%rip),%rax
mov    (%rax),%r15d
mov    0x2bc3(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1493 <main+0x2c3>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1080 <tcgetattr@plt>
test   %rax,%rax
jne    145a <main+0x28a>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <cfsetospeed@plt>
mov    0x2b72(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1090 <tcsetattr@plt>
cmpl   $0x0,0xc(%rsp)
je     14b2 <main+0x2e2>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     14e8 <main+0x318>
test   %eax,%eax
jle    14c3 <main+0x2f3>
xor    %ebx,%ebx
test   %r13d,%r13d
je     12ad <main+0xdd>
lea    0xc92(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ad <main+0xdd>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a8 <main+0xd8>
test   %r13d,%r13d
je     1515 <main+0x345>
lea    0xc7a(%rip),%rdi
call   1030 <puts@plt>
test   %r13d,%r13d
jne    1509 <main+0x339>
jmp    1515 <main+0x345>
mov    0x2aa7(%rip),%rax
mov    (%rax),%edi
lea    0xbe9(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a8 <main+0xd8>
mov    0x2a89(%rip),%rax
mov    (%rax),%edi
lea    0xbfe(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xc0f(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   10e0 <sleep@plt>
test   %r13d,%r13d
jne    1509 <main+0x339>
jmp    1515 <main+0x345>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [7 x i8] c"dvp:b:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [68 x i8] c"usage: fpacwdog [-v] [-d] [-b baudrate] [-p seconds] serial_device\0A\00"
@optind = global i32 0
@.str.2 = [23 x i8] c"Period : %d second(s)\0A\00"
@.str.3 = [13 x i8] c"Baudrate %d\0A\00"
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@.str.4 = [21 x i8] c"Invalid baudrate %d\0A\00"
@O_RDWR = global i32 0
@.str.5 = [30 x i8] c"Cannot open serial device %s\0A\00"
@TCSANOW = global i32 0
@.str.6 = [31 x i8] c"fpacwdog cannot become daemon\0A\00"
@.str.7 = [22 x i8] c"Background mode [%d]\0A\00"
@.str.8 = [17 x i8] c"Foreground mode\0A\00"
@.str.9 = [12 x i8] c"Sending CR\0A\00"
@.str.10 = [2 x i8] c"\0D\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 i8*
%9 = alloca %struct.termios
%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 60, i32* %10
store i32 50, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %6
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %36
20: ; preds = %15
%21 = load i32, i32* %6
switch i32 %21, label %35 [
i32 112, label %22
i32 98, label %25
i32 100, label %28
i32 118, label %29
i32 63, label %32
i32 58, label %32
]
22: ; preds = %20
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %10
br label %35
25: ; preds = %20
%26 = load i32, i32* @optarg
%27 = call i32 @atoi(i32 %26)
store i32 %27, i32* %11
br label %35
28: ; preds = %20
store i32 0, i32* %12
br label %35
29: ; preds = %20
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 1
store i32 %31, i32* %13
br label %35
32: ; preds = %20, %20
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %147
35: ; preds = %20, %29, %28, %25, %22
br label %15
36: ; preds = %15
%37 = load i32, i32* @optind
%38 = load i32, i32* %4
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %147
43: ; preds = %36
%44 = load i8**, i8*** %5
%45 = load i32, i32* @optind
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = load i32, i32* %13
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %43
%52 = load i32, i32* %10
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %11
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %51, %43
%57 = load i32, i32* %11
switch i32 %57, label %84 [
i32 50, label %58
i32 75, label %60
i32 110, label %62
i32 150, label %64
i32 200, label %66
i32 300, label %68
i32 600, label %70
i32 1200, label %72
i32 2400, label %74
i32 4800, label %76
i32 9600, label %78
i32 19200, label %80
i32 38400, label %82
]
58: ; preds = %56
%59 = load i32, i32* @B50
store i32 %59, i32* %11
br label %88
60: ; preds = %56
%61 = load i32, i32* @B75
store i32 %61, i32* %11
br label %88
62: ; preds = %56
%63 = load i32, i32* @B110
store i32 %63, i32* %11
br label %88
64: ; preds = %56
%65 = load i32, i32* @B150
store i32 %65, i32* %11
br label %88
66: ; preds = %56
%67 = load i32, i32* @B200
store i32 %67, i32* %11
br label %88
68: ; preds = %56
%69 = load i32, i32* @B300
store i32 %69, i32* %11
br label %88
70: ; preds = %56
%71 = load i32, i32* @B600
store i32 %71, i32* %11
br label %88
72: ; preds = %56
%73 = load i32, i32* @B1200
store i32 %73, i32* %11
br label %88
74: ; preds = %56
%75 = load i32, i32* @B2400
store i32 %75, i32* %11
br label %88
76: ; preds = %56
%77 = load i32, i32* @B4800
store i32 %77, i32* %11
br label %88
78: ; preds = %56
%79 = load i32, i32* @B9600
store i32 %79, i32* %11
br label %88
80: ; preds = %56
%81 = load i32, i32* @B19200
store i32 %81, i32* %11
br label %88
82: ; preds = %56
%83 = load i32, i32* @B38400
store i32 %83, i32* %11
br label %88
84: ; preds = %56
%85 = load i32, i32* @stderr
%86 = load i32, i32* %11
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %86)
store i32 1, i32* %3
br label %147
88: ; preds = %82, %80, %78, %76, %74, %72, %70, %68, %66, %64, %62, %60, %58
%89 = load i8*, i8** %8
%90 = load i32, i32* @O_RDWR
%91 = call i32 @open(i8* %89, i32 %90)
store i32 %91, i32* %7
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %88
%95 = load i32, i32* @stderr
%96 = load i8*, i8** %8
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %96)
store i32 1, i32* %3
br label %147
98: ; preds = %88
%99 = load i32, i32* %7
%100 = call i64 @tcgetattr(i32 %99, %struct.termios* %9)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %108
102: ; preds = %98
%103 = load i32, i32* %11
%104 = call i32 @cfsetospeed(%struct.termios* %9, i32 %103)
%105 = load i32, i32* %7
%106 = load i32, i32* @TCSANOW
%107 = call i32 @tcsetattr(i32 %105, i32 %106, %struct.termios* %9)
br label %108
108: ; preds = %102, %98
%109 = load i32, i32* %12
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %130
111: ; preds = %108
%112 = call i32 (...) @fork()
store i32 %112, i32* %14
%113 = load i32, i32* %14
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %119
115: ; preds = %111
%116 = load i32, i32* @stderr
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %111
%120 = load i32, i32* %14
%121 = icmp sgt i32 %120, 0
br i1 %121, label %122, label %129
122: ; preds = %119
%123 = load i32, i32* %13
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %122
%126 = load i32, i32* %14
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %125, %122
store i32 0, i32* %3
br label %147
129: ; preds = %119
br label %136
130: ; preds = %108
%131 = load i32, i32* %13
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %130
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %135
135: ; preds = %133, %130
br label %136
136: ; preds = %135, %129
br label %137
137: ; preds = %142, %136
%138 = load i32, i32* %13
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %142
140: ; preds = %137
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %142
142: ; preds = %140, %137
%143 = load i32, i32* %7
%144 = call i32 @write(i32 %143, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%145 = load i32, i32* %10
%146 = call i32 @sleep(i32 %145)
br label %137
147: ; preds = %128, %94, %84, %40, %32
%148 = load i32, i32* %3
ret i32 %148
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [7 x i8] c"dvp:b:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [68 x i8] c"usage: fpacwdog [-v] [-d] [-b baudrate] [-p seconds] serial_device\0A\00"
@optind = global i32 0
@.str.2 = [23 x i8] c"Period : %d second(s)\0A\00"
@.str.3 = [13 x i8] c"Baudrate %d\0A\00"
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@.str.4 = [21 x i8] c"Invalid baudrate %d\0A\00"
@O_RDWR = global i32 0
@.str.5 = [30 x i8] c"Cannot open serial device %s\0A\00"
@TCSANOW = global i32 0
@.str.6 = [31 x i8] c"fpacwdog cannot become daemon\0A\00"
@.str.7 = [22 x i8] c"Background mode [%d]\0A\00"
@.str.10 = [2 x i8] c"\0D\00"
@str = [11 x i8] c"Sending CR\00"
@str.11 = [16 x i8] c"Foreground mode\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
br label %5
5: ; preds = %21, %2
%6 = phi i32 [ %23, %21 ], [ 60, %2 ]
%7 = phi i32 [ %11, %21 ], [ 50, %2 ]
%8 = phi i32 [ %15, %21 ], [ 1, %2 ]
%9 = phi i32 [ %18, %21 ], [ 0, %2 ]
br label %10
10: ; preds = %5, %24
%11 = phi i32 [ %7, %5 ], [ %26, %24 ]
%12 = phi i32 [ %8, %5 ], [ %15, %24 ]
%13 = phi i32 [ %9, %5 ], [ %18, %24 ]
br label %14
14: ; preds = %19, %10
%15 = phi i32 [ %12, %10 ], [ 0, %19 ]
%16 = phi i32 [ %13, %10 ], [ %18, %19 ]
br label %17
17: ; preds = %14, %27
%18 = phi i32 [ %16, %14 ], [ %28, %27 ]
br label %19
19: ; preds = %17, %19
%20 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %20, label %19 [
i32 -1, label %32
i32 112, label %21
i32 98, label %24
i32 100, label %14
i32 118, label %27
i32 63, label %29
i32 58, label %29
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = tail call i32 @atoi(i32 %22)
br label %5
24: ; preds = %19
%25 = load i32, i32* @optarg
%26 = tail call i32 @atoi(i32 %25)
br label %10
27: ; preds = %19
%28 = add nsw i32 %18, 1
br label %17
29: ; preds = %19, %19
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %101
32: ; preds = %19
%33 = load i32, i32* @optind
%34 = icmp eq i32 %33, %0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %101
38: ; preds = %32
%39 = sext i32 %33 to i64
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = icmp eq i32 %18, 0
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %46
46: ; preds = %43, %38
switch i32 %11, label %59 [
i32 50, label %62
i32 75, label %47
i32 110, label %48
i32 150, label %49
i32 200, label %50
i32 300, label %51
i32 600, label %52
i32 1200, label %53
i32 2400, label %54
i32 4800, label %55
i32 9600, label %56
i32 19200, label %57
i32 38400, label %58
]
47: ; preds = %46
br label %62
48: ; preds = %46
br label %62
49: ; preds = %46
br label %62
50: ; preds = %46
br label %62
51: ; preds = %46
br label %62
52: ; preds = %46
br label %62
53: ; preds = %46
br label %62
54: ; preds = %46
br label %62
55: ; preds = %46
br label %62
56: ; preds = %46
br label %62
57: ; preds = %46
br label %62
58: ; preds = %46
br label %62
59: ; preds = %46
%60 = load i32, i32* @stderr
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %101
62: ; preds = %46, %58, %57, %56, %55, %54, %53, %52, %51, %50, %49, %48, %47
%63 = phi i32* [ @B38400, %58 ], [ @B19200, %57 ], [ @B9600, %56 ], [ @B4800, %55 ], [ @B2400, %54 ], [ @B1200, %53 ], [ @B600, %52 ], [ @B300, %51 ], [ @B200, %50 ], [ @B150, %49 ], [ @B110, %48 ], [ @B75, %47 ], [ @B50, %46 ]
%64 = load i32, i32* %63
%65 = load i32, i32* @O_RDWR
%66 = tail call i32 @open(i8* %41, i32 %65)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %101
71: ; preds = %62
%72 = call i64 @tcgetattr(i32 %66, %struct.termios* %3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = call i32 @cfsetospeed(%struct.termios* %3, i32 %64)
%76 = load i32, i32* @TCSANOW
%77 = call i32 @tcsetattr(i32 %66, i32 %76, %struct.termios* %3)
br label %78
78: ; preds = %74, %71
%79 = icmp eq i32 %15, 0
br i1 %79, label %92, label %80
80: ; preds = %78
%81 = call i32 (...) @fork()
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %80
%88 = icmp sgt i32 %81, 0
br i1 %88, label %89, label %95
89: ; preds = %87
br i1 %42, label %101, label %90
90: ; preds = %89
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %81)
br label %101
92: ; preds = %78
br i1 %42, label %98, label %93
93: ; preds = %92
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
br label %95
95: ; preds = %87, %93, %98
br i1 %42, label %98, label %96
96: ; preds = %95
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %98
98: ; preds = %92, %96, %95
%99 = call i32 @write(i32 %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%100 = call i32 @sleep(i32 %6)
br label %95
101: ; preds = %89, %90, %68, %59, %35, %29
%102 = phi i32 [ 1, %29 ], [ 1, %35 ], [ 1, %59 ], [ 1, %68 ], [ 0, %90 ], [ 0, %89 ]
ret i32 %102
}