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

/* Variables and functions */
int EOF;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ _exit(int);
int atoi(int /*<<< orphan*/);
int errno;
scalar_t__ execv(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
scalar_t__ malloc(int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid = 0, w;
  int status = 0, opt, n;
  int init_speed = 0;
  char *dev = NULL;
  char *bdaddr = NULL;
  printf(" Starting nv_hciattach deamon to configure BT Chip\n");
  while ((opt = getopt(argc, argv, "bnpt:s:")) != EOF) {
    switch (opt) {
    case 'b':
    case 'n':
    case 'p':
    case 't':
      break;
    case 's':
      init_speed = atoi(optarg);
      break;
    default:
      usage();
      exit(1);
    }
  }
  n = argc - optind;
  if (n < 2) {
    usage();
    exit(1);
  }
  for (n = 0; optind < argc; n++, optind++) {
    char *opt;
    opt = argv[optind];
    switch (n) {
    case 0:
      dev = (char *)malloc(strlen(opt) + 10);
      if (dev == NULL) {
        printf("nv_hciatatch:Error in memory allocation");
        return -1;
      }
      dev[0] = 0;
      if (!strchr(opt, '/'))
        strcpy(dev, "/dev/");
      strcat(dev, opt);
      break;
    case 4:
      bdaddr = argv[optind];
      break;
    }
  }
  if (dev == NULL) {
    printf("nv_hciattach: tty device not specified");
    return -1;
  }
  pid = fork();
  if (pid == 0) {
    printf("Using bccmd to configure the CSR Chip\n");
    char *bccmd_argv[15] = {NULL};
    int i = 0;
    bccmd_argv[i++] = (char *)"/system/bin/bccmd";
    bccmd_argv[i++] = (char *)"-t";
    bccmd_argv[i++] = (char *)"bcsp";
    bccmd_argv[i++] = (char *)"-d";
    bccmd_argv[i++] = (char *)dev;
    bccmd_argv[i++] = (char *)"psload";
    bccmd_argv[i++] = (char *)"-r";
    bccmd_argv[i++] = "/etc/bluez/bluecore6.psr";
    bccmd_argv[i++] = NULL;
    printf("BCCMD Command:");
    for (i = 0; bccmd_argv[i] != NULL; i++)
      printf("%s ", bccmd_argv[i]);
    printf("\n");
    if (execv("/system/bin/bccmd", bccmd_argv) < 0) {
      printf("cannot execve('%s'): %s\n", "/system/bin/bccmd", strerror(errno));
    }
    free(dev);
    _exit(127);
  } else if (pid < 0) {
    free(dev);
    printf("fork() with error:%d(%s) %d\n", errno, strerror(errno), pid);
    return -1;
  } else {
    do {
      w = waitpid(pid, &status, WUNTRACED);
      if (w == -1) {
        printf("waitpid");
        free(dev);
        return -1;
      }
      if (WIFEXITED(status)) {
        printf("exited, status=%d\n", WEXITSTATUS(status));
      } else if (WIFSIGNALED(status)) {
        printf("killed by signal %d\n", WTERMSIG(status));
      } else if (WIFSTOPPED(status)) {
        printf("stopped by signal %d\n", WSTOPSIG(status));
      }
    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
  }
  printf("Starting Bluetooth hciattach with arguments : \n");
  char *hciattach_argv[15] = {NULL};
  int j = 0;
  hciattach_argv[j++] = "/system/bin/hciattach";
  for (; j < argc; j++)
    hciattach_argv[j] = argv[j];
  hciattach_argv[j++] = NULL;
  printf("hciattach command: ");
  for (j = 0; hciattach_argv[j] != NULL; j++)
    printf("%s  ", hciattach_argv[j]);
  printf("\n");
  if (execv("/system/bin/hciattach", hciattach_argv) < 0) {
    printf("cannot execve('%s'): %s\n", "/system/bin/hciattach",
           strerror(errno));
  }
  free(dev);
  printf("Bluetooth HCI Driver initialisation Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd69(%rip),%rdx
call   1110 <getopt@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d06(%rip),%rcx
cmp    (%rcx),%eax
je     137a <main+0x10a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x148(%rbp)
sub    $0x62,%eax
je     1349 <main+0xd9>
jmp    12f9 <main+0x89>
mov    -0x148(%rbp),%eax
sub    $0x6e,%eax
je     1349 <main+0xd9>
jmp    130d <main+0x9d>
mov    -0x148(%rbp),%eax
sub    $0x70,%eax
je     1349 <main+0xd9>
jmp    1321 <main+0xb1>
mov    -0x148(%rbp),%eax
sub    $0x73,%eax
je     134e <main+0xde>
jmp    1335 <main+0xc5>
mov    -0x148(%rbp),%eax
sub    $0x74,%eax
jne    1364 <main+0xf4>
jmp    1349 <main+0xd9>
jmp    1375 <main+0x105>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   1120 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    1375 <main+0x105>
mov    $0x0,%al
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
jmp    12bd <main+0x4d>
mov    -0x8(%rbp),%eax
mov    0x2c54(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    13a4 <main+0x134>
mov    $0x0,%al
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    14b7 <main+0x247>
mov    -0x10(%rbp),%rax
mov    0x2c10(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14c(%rbp)
test   %eax,%eax
je     13fd <main+0x18d>
jmp    13e9 <main+0x179>
mov    -0x14c(%rbp),%eax
sub    $0x4,%eax
je     1479 <main+0x209>
jmp    148f <main+0x21f>
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0xa,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1439 <main+0x1c9>
lea    0xc16(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a0f <main+0x79f>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
cmp    $0x0,%eax
jne    1467 <main+0x1f7>
mov    -0x38(%rbp),%rdi
lea    0xc02(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1130 <strcat@plt>
jmp    148f <main+0x21f>
mov    -0x10(%rbp),%rax
mov    0x2b54(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
jmp    1494 <main+0x224>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2b34(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2b28(%rip),%rax
mov    %ecx,(%rax)
jmp    13ab <main+0x13b>
cmpq   $0x0,-0x38(%rbp)
jne    14dc <main+0x26c>
lea    0xba1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a0f <main+0x79f>
mov    $0x0,%al
call   1190 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    170c <main+0x49c>
lea    0xb98(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1090 <memset@plt>
movl   $0x0,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xb81(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xb71(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xb52(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xb35(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0x38(%rbp),%rcx
mov    -0xc4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc4(%rbp)
cltq
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xaf7(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xadc(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
lea    0xabd(%rip),%rcx
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc4(%rbp)
cltq
movq   $0x0,-0xc0(%rbp,%rax,8)
lea    0xaa8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0xc4(%rbp)
movslq -0xc4(%rbp),%rax
cmpq   $0x0,-0xc0(%rbp,%rax,8)
je     16a8 <main+0x438>
movslq -0xc4(%rbp),%rax
mov    -0xc0(%rbp,%rax,8),%rsi
ff
lea    0xa7a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1661 <main+0x3f1>
lea    0xb06(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0x9f4(%rip),%rdi
call   1180 <execv@plt>
cmp    $0x0,%rax
jge    16f9 <main+0x489>
mov    0x28e6(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
mov    %rax,%rdx
lea    0xa20(%rip),%rdi
lea    0x9c6(%rip),%rsi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7f,%edi
call   1040 <_exit@plt>
cmpq   $0x0,-0x18(%rbp)
jge    1764 <main+0x4f4>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2899(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    0x288a(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
mov    -0x150(%rbp),%esi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
lea    0x9d3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a0f <main+0x79f>
jmp    1769 <main+0x4f9>
mov    -0x18(%rbp),%rdi
mov    0x2854(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rsi
call   1100 <waitpid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    17b1 <main+0x541>
lea    0x9ac(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a0f <main+0x79f>
mov    -0x24(%rbp),%edi
call   1140 <WIFEXITED@plt>
cmp    $0x0,%rax
je     17e0 <main+0x570>
mov    -0x24(%rbp),%edi
call   10f0 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0x975(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1843 <main+0x5d3>
mov    -0x24(%rbp),%edi
call   10a0 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     180f <main+0x59f>
mov    -0x24(%rbp),%edi
call   10d0 <WTERMSIG@plt>
mov    %eax,%esi
lea    0x959(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    183e <main+0x5ce>
mov    -0x24(%rbp),%edi
call   10b0 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1839 <main+0x5c9>
mov    -0x24(%rbp),%edi
call   1170 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0x93f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    183e <main+0x5ce>
jmp    1843 <main+0x5d3>
jmp    1848 <main+0x5d8>
mov    -0x24(%rbp),%edi
call   1140 <WIFEXITED@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x151(%rbp)
jne    187c <main+0x60c>
mov    -0x24(%rbp),%edi
call   10a0 <WIFSIGNALED@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x151(%rbp)
mov    -0x151(%rbp),%al
test   $0x1,%al
jne    1769 <main+0x4f9>
jmp    188f <main+0x61f>
jmp    1894 <main+0x624>
lea    0x8ec(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1090 <memset@plt>
movl   $0x0,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x144(%rbp)
cltq
lea    0x8de(%rip),%rcx
mov    %rcx,-0x140(%rbp,%rax,8)
ff
mov    -0x144(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1922 <main+0x6b2>
mov    -0x10(%rbp),%rax
movslq -0x144(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x144(%rbp),%rax
mov    %rcx,-0x140(%rbp,%rax,8)
ff
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    18e1 <main+0x671>
mov    -0x144(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x144(%rbp)
cltq
movq   $0x0,-0x140(%rbp,%rax,8)
lea    0x885(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x144(%rbp)
movslq -0x144(%rbp),%rax
cmpq   $0x0,-0x140(%rbp,%rax,8)
je     19a0 <main+0x730>
movslq -0x144(%rbp),%rax
mov    -0x140(%rbp,%rax,8),%rsi
ff
lea    0x85c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    1959 <main+0x6e9>
lea    0x80e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x140(%rbp),%rsi
lea    0x7fb(%rip),%rdi
call   1180 <execv@plt>
cmp    $0x0,%rax
jge    19f1 <main+0x781>
mov    0x25ee(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
mov    %rax,%rdx
lea    0x728(%rip),%rdi
lea    0x7cd(%rip),%rsi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
lea    0x7e5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
movl   $0x0,0xc(%rsp)
lea    0xea5(%rip),%rdi
call   1070 <puts@plt>
lea    0xd3e(%rip),%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1130 <getopt@plt>
mov    0x2d0c(%rip),%r14
cmp    (%r14),%eax
jne    137c <main+0xec>
mov    0x2cf4(%rip),%r13
mov    0x0(%r13),%eax
mov    %r15d,%ecx
sub    %eax,%ecx
cmp    $0x2,%ecx
jl     13ca <main+0x13a>
cmp    %r15d,%eax
jge    15d5 <main+0x345>
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    132f <main+0x9f>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1150 <strcat@plt>
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %eax,0x0(%r13)
cmp    %r15d,%eax
jge    13db <main+0x14b>
sub    $0x1,%r12d
jae    131f <main+0x8f>
cltq
mov    (%rbx,%rax,8),%rbp
mov    %rbp,%rdi
call   1080 <strlen@plt>
lea    0xa(%rax),%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     15de <main+0x34e>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1090 <strchr@plt>
test   %eax,%eax
jne    1310 <main+0x80>
mov    %r14,%rdi
lea    0xcbb(%rip),%rsi
call   1060 <strcpy@plt>
jmp    1310 <main+0x80>
mov    $0x45001,%r13d
lea    0xc77(%rip),%rbp
mov    0x2c68(%rip),%r12
jmp    13b7 <main+0x127>
mov    (%r12),%edi
call   1140 <atoi@plt>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1130 <getopt@plt>
cmp    (%r14),%eax
je     12dd <main+0x4d>
add    $0xffffff9e,%eax
cmp    $0x12,%eax
ja     13ca <main+0x13a>
bt     %eax,%r13d
jb     13a0 <main+0x110>
cmp    $0x11,%eax
je     1392 <main+0x102>
xor    %eax,%eax
call   1100 <usage@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
test   %r14,%r14
je     15d5 <main+0x345>
xor    %eax,%eax
call   11b0 <fork@plt>
test   %rax,%rax
je     164b <main+0x3bb>
mov    %rax,%r12
js     1603 <main+0x373>
mov    0x2bc4(%rip),%rbp
lea    0xc(%rsp),%r13
nopl   0x0(%rax)
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1120 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     1633 <main+0x3a3>
mov    0xc(%rsp),%edi
call   1160 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     1450 <main+0x1c0>
call   1110 <WEXITSTATUS@plt>
lea    0xca8(%rip),%rdi
jmp    1490 <main+0x200>
nopl   0x0(%rax,%rax,1)
call   10b0 <WIFSIGNALED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     146c <main+0x1dc>
call   10f0 <WTERMSIG@plt>
lea    0xc97(%rip),%rdi
jmp    1490 <main+0x200>
call   10d0 <WIFSTOPPED@plt>
test   %rax,%rax
je     1499 <main+0x209>
mov    0xc(%rsp),%edi
call   1190 <WSTOPSIG@plt>
lea    0xc90(%rip),%rdi
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0xc(%rsp),%edi
call   1160 <WIFEXITED@plt>
test   %rax,%rax
jne    14b9 <main+0x229>
mov    0xc(%rsp),%edi
call   10b0 <WIFSIGNALED@plt>
test   %rax,%rax
je     1410 <main+0x180>
lea    0xcce(%rip),%rdi
call   1070 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x80(%rsp)
lea    0xc2e(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%eax
cmp    $0x2,%r15d
jl     152a <main+0x29a>
lea    0x18(%rsp),%rdi
add    $0x8,%rbx
lea    -0x1(%r15),%edx
shl    $0x3,%rdx
mov    %rbx,%rsi
call   10c0 <memcpy@plt>
mov    %r15d,%eax
movq   $0x0,0x10(%rsp,%rax,8)
lea    0xc08(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     1577 <main+0x2e7>
lea    0x18(%rsp),%rbp
lea    0xbff(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1560 <main+0x2d0>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xba4(%rip),%rdi
lea    0x10(%rsp),%rsi
call   11a0 <execv@plt>
test   %rax,%rax
jns    15bd <main+0x32d>
mov    0x2a22(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
lea    0xb04(%rip),%rdi
lea    0xb79(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xbf1(%rip),%rdi
call   1070 <puts@plt>
xor    %eax,%eax
jmp    15f1 <main+0x361>
lea    0xa5a(%rip),%rdi
jmp    15e5 <main+0x355>
lea    0xa23(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x29ae(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1180 <strerror@plt>
lea    0xaa7(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    15ec <main+0x35c>
lea    0xaac(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    15ec <main+0x35c>
lea    0xb95(%rip),%rdi
call   1070 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movq   $0x0,0x80(%rsp)
lea    0x9e1(%rip),%rbx
mov    %rbx,0x10(%rsp)
lea    0x18(%rsp),%rbp
lea    0x9e2(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0x9d9(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0x9d2(%rip),%rax
mov    %rax,0x28(%rsp)
mov    %r14,0x30(%rsp)
lea    0x9c4(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0x9bf(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0x9b6(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0x9c3(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x9c4(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x0(%rbp),%rbx
add    $0x8,%rbp
test   %rbx,%rbx
jne    16f0 <main+0x460>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x942(%rip),%rdi
lea    0x10(%rsp),%rsi
call   11a0 <execv@plt>
test   %rax,%rax
jns    1750 <main+0x4c0>
mov    0x288f(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
lea    0x971(%rip),%rdi
lea    0x917(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x7f,%edi
call   1050 <_exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c" Starting nv_hciattach deamon to configure BT Chip\0A\00"
@.str.1 = [8 x i8] c"bnpt:s:\00"
@EOF = global i32 0
@optarg = global i32 0
@optind = global i32 0
@.str.2 = [40 x i8] c"nv_hciatatch:Error in memory allocation\00"
@.str.3 = [6 x i8] c"/dev/\00"
@.str.4 = [39 x i8] c"nv_hciattach: tty device not specified\00"
@.str.5 = [39 x i8] c"Using bccmd to configure the CSR Chip\0A\00"
@.str.6 = [18 x i8] c"/system/bin/bccmd\00"
@.str.7 = [3 x i8] c"-t\00"
@.str.8 = [5 x i8] c"bcsp\00"
@.str.9 = [3 x i8] c"-d\00"
@.str.10 = [7 x i8] c"psload\00"
@.str.11 = [3 x i8] c"-r\00"
@.str.12 = [25 x i8] c"/etc/bluez/bluecore6.psr\00"
@.str.13 = [15 x i8] c"BCCMD Command:\00"
@.str.14 = [4 x i8] c"%s \00"
@.str.15 = [2 x i8] c"\0A\00"
@.str.16 = [25 x i8] c"cannot execve('%s'): %s\0A\00"
@errno = global i32 0
@.str.17 = [29 x i8] c"fork() with error:%d(%s) %d\0A\00"
@WUNTRACED = global i32 0
@.str.18 = [8 x i8] c"waitpid\00"
@.str.19 = [19 x i8] c"exited, status=%d\0A\00"
@.str.20 = [21 x i8] c"killed by signal %d\0A\00"
@.str.21 = [22 x i8] c"stopped by signal %d\0A\00"
@.str.22 = [48 x i8] c"Starting Bluetooth hciattach with arguments : \0A\00"
@.str.23 = [22 x i8] c"/system/bin/hciattach\00"
@.str.24 = [20 x i8] c"hciattach command: \00"
@.str.25 = [5 x i8] c"%s \00"
@.str.26 = [43 x i8] c"Bluetooth HCI Driver initialisation Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [15 x i8*]
%16 = alloca i32
%17 = alloca [15 x i8*]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i32 0, i32* %8
store i32 0, i32* %11
store i8* null, i8** %12
store i8* null, i8** %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %35, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %23, i32* %9
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %36
26: ; preds = %20
%27 = load i32, i32* %9
switch i32 %27, label %32 [
i32 98, label %28
i32 110, label %28
i32 112, label %28
i32 116, label %28
i32 115, label %29
]
28: ; preds = %26, %26, %26, %26
br label %35
29: ; preds = %26
%30 = load i32, i32* @optarg
%31 = call i32 @atoi(i32 %30)
store i32 %31, i32* %11
br label %35
32: ; preds = %26
%33 = call i32 (...) @usage()
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29, %28
br label %20
36: ; preds = %20
%37 = load i32, i32* %4
%38 = load i32, i32* @optind
%39 = sub nsw i32 %37, %38
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 2
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 (...) @usage()
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
store i32 0, i32* %10
br label %46
46: ; preds = %87, %45
%47 = load i32, i32* @optind
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %92
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* @optind
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
store i8* %55, i8** %14
%56 = load i32, i32* %10
switch i32 %56, label %86 [
i32 0, label %57
i32 4, label %80
]
57: ; preds = %50
%58 = load i8*, i8** %14
%59 = call i32 @strlen(i8* %58)
%60 = add nsw i32 %59, 10
%61 = call i64 @malloc(i32 %60)
%62 = inttoptr i64 %61 to i8*
store i8* %62, i8** %12
%63 = load i8*, i8** %12
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %67
65: ; preds = %57
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %289
67: ; preds = %57
%68 = load i8*, i8** %12
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 0, i8* %69
%70 = load i8*, i8** %14
%71 = call i32 @strchr(i8* %70, i8 signext 47)
%72 = icmp ne i32 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %67
%74 = load i8*, i8** %12
%75 = call i32 @strcpy(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %76
76: ; preds = %73, %67
%77 = load i8*, i8** %12
%78 = load i8*, i8** %14
%79 = call i32 @strcat(i8* %77, i8* %78)
br label %86
80: ; preds = %50
%81 = load i8**, i8*** %5
%82 = load i32, i32* @optind
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = load i8*, i8** %84
store i8* %85, i8** %13
br label %86
86: ; preds = %50, %80, %76
br label %87
87: ; preds = %86
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
store i32 %89, i32* %10
%90 = load i32, i32* @optind
%91 = add nsw i32 %90, 1
store i32 %91, i32* @optind
br label %46
92: ; preds = %46
%93 = load i8*, i8** %12
%94 = icmp eq i8* %93, null
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %289
97: ; preds = %92
%98 = call i64 (...) @fork()
store i64 %98, i64* %6
%99 = load i64, i64* %6
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %170
101: ; preds = %97
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%103 = bitcast [15 x i8*]* %15 to i8*
store i32 0, i32* %16
%104 = load i32, i32* %16
%105 = add nsw i32 %104, 1
store i32 %105, i32* %16
%106 = sext i32 %104 to i64
%107 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %106
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %107
%108 = load i32, i32* %16
%109 = add nsw i32 %108, 1
store i32 %109, i32* %16
%110 = sext i32 %108 to i64
%111 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %110
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %111
%112 = load i32, i32* %16
%113 = add nsw i32 %112, 1
store i32 %113, i32* %16
%114 = sext i32 %112 to i64
%115 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %114
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8** %115
%116 = load i32, i32* %16
%117 = add nsw i32 %116, 1
store i32 %117, i32* %16
%118 = sext i32 %116 to i64
%119 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %118
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8** %119
%120 = load i8*, i8** %12
%121 = load i32, i32* %16
%122 = add nsw i32 %121, 1
store i32 %122, i32* %16
%123 = sext i32 %121 to i64
%124 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %123
store i8* %120, i8** %124
%125 = load i32, i32* %16
%126 = add nsw i32 %125, 1
store i32 %126, i32* %16
%127 = sext i32 %125 to i64
%128 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %127
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8** %128
%129 = load i32, i32* %16
%130 = add nsw i32 %129, 1
store i32 %130, i32* %16
%131 = sext i32 %129 to i64
%132 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %131
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8** %132
%133 = load i32, i32* %16
%134 = add nsw i32 %133, 1
store i32 %134, i32* %16
%135 = sext i32 %133 to i64
%136 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %135
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i8** %136
%137 = load i32, i32* %16
%138 = add nsw i32 %137, 1
store i32 %138, i32* %16
%139 = sext i32 %137 to i64
%140 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %139
store i8* null, i8** %140
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %16
br label %142
142: ; preds = %154, %101
%143 = load i32, i32* %16
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %144
%146 = load i8*, i8** %145
%147 = icmp ne i8* %146, null
br i1 %147, label %148, label %157
148: ; preds = %142
%149 = load i32, i32* %16
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 %150
%152 = load i8*, i8** %151
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8* %152)
br label %154
154: ; preds = %148
%155 = load i32, i32* %16
%156 = add nsw i32 %155, 1
store i32 %156, i32* %16
br label %142
157: ; preds = %142
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%159 = getelementptr inbounds [15 x i8*], [15 x i8*]* %15, i64 0, i64 0
%160 = call i64 @execv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %159)
%161 = icmp slt i64 %160, 0
br i1 %161, label %162, label %166
162: ; preds = %157
%163 = load i32, i32* @errno
%164 = call i8* @strerror(i32 %163)
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %164)
br label %166
166: ; preds = %162, %157
%167 = load i8*, i8** %12
%168 = call i32 @free(i8* %167)
%169 = call i32 @_exit(i32 127)
unreachable
170: ; preds = %97
%171 = load i64, i64* %6
%172 = icmp slt i64 %171, 0
br i1 %172, label %173, label %181
173: ; preds = %170
%174 = load i8*, i8** %12
%175 = call i32 @free(i8* %174)
%176 = load i32, i32* @errno
%177 = load i32, i32* @errno
%178 = call i8* @strerror(i32 %177)
%179 = load i64, i64* %6
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0), i32 %176, i8* %178, i64 %179)
store i32 -1, i32* %3
br label %289
181: ; preds = %170
br label %182
182: ; preds = %228, %181
%183 = load i64, i64* %6
%184 = load i32, i32* @WUNTRACED
%185 = call i64 @waitpid(i64 %183, i32* %8, i32 %184)
store i64 %185, i64* %7
%186 = load i64, i64* %7
%187 = icmp eq i64 %186, -1
br i1 %187, label %188, label %192
188: ; preds = %182
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0))
%190 = load i8*, i8** %12
%191 = call i32 @free(i8* %190)
store i32 -1, i32* %3
br label %289
192: ; preds = %182
%193 = load i32, i32* %8
%194 = call i64 @WIFEXITED(i32 %193)
%195 = icmp ne i64 %194, 0
br i1 %195, label %196, label %200
196: ; preds = %192
%197 = load i32, i32* %8
%198 = call i32 @WEXITSTATUS(i32 %197)
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i32 %198)
br label %218
200: ; preds = %192
%201 = load i32, i32* %8
%202 = call i64 @WIFSIGNALED(i32 %201)
%203 = icmp ne i64 %202, 0
br i1 %203, label %204, label %208
204: ; preds = %200
%205 = load i32, i32* %8
%206 = call i32 @WTERMSIG(i32 %205)
%207 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0), i32 %206)
br label %217
208: ; preds = %200
%209 = load i32, i32* %8
%210 = call i64 @WIFSTOPPED(i32 %209)
%211 = icmp ne i64 %210, 0
br i1 %211, label %212, label %216
212: ; preds = %208
%213 = load i32, i32* %8
%214 = call i32 @WSTOPSIG(i32 %213)
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %214)
br label %216
216: ; preds = %212, %208
br label %217
217: ; preds = %216, %204
br label %218
218: ; preds = %217, %196
br label %219
219: ; preds = %218
%220 = load i32, i32* %8
%221 = call i64 @WIFEXITED(i32 %220)
%222 = icmp ne i64 %221, 0
br i1 %222, label %228, label %223
223: ; preds = %219
%224 = load i32, i32* %8
%225 = call i64 @WIFSIGNALED(i32 %224)
%226 = icmp ne i64 %225, 0
%227 = xor i1 %226, true
br label %228
228: ; preds = %223, %219
%229 = phi i1 [ false, %219 ], [ %227, %223 ]
br i1 %229, label %182, label %230
230: ; preds = %228
br label %231
231: ; preds = %230
br label %232
232: ; preds = %231
%233 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.22, i64 0, i64 0))
%234 = bitcast [15 x i8*]* %17 to i8*
store i32 0, i32* %18
%235 = load i32, i32* %18
%236 = add nsw i32 %235, 1
store i32 %236, i32* %18
%237 = sext i32 %235 to i64
%238 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 %237
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8** %238
br label %239
239: ; preds = %252, %232
%240 = load i32, i32* %18
%241 = load i32, i32* %4
%242 = icmp slt i32 %240, %241
br i1 %242, label %243, label %255
243: ; preds = %239
%244 = load i8**, i8*** %5
%245 = load i32, i32* %18
%246 = sext i32 %245 to i64
%247 = getelementptr inbounds i8*, i8** %244, i64 %246
%248 = load i8*, i8** %247
%249 = load i32, i32* %18
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 %250
store i8* %248, i8** %251
br label %252
252: ; preds = %243
%253 = load i32, i32* %18
%254 = add nsw i32 %253, 1
store i32 %254, i32* %18
br label %239
255: ; preds = %239
%256 = load i32, i32* %18
%257 = add nsw i32 %256, 1
store i32 %257, i32* %18
%258 = sext i32 %256 to i64
%259 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 %258
store i8* null, i8** %259
%260 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.24, i64 0, i64 0))
store i32 0, i32* %18
br label %261
261: ; preds = %273, %255
%262 = load i32, i32* %18
%263 = sext i32 %262 to i64
%264 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 %263
%265 = load i8*, i8** %264
%266 = icmp ne i8* %265, null
br i1 %266, label %267, label %276
267: ; preds = %261
%268 = load i32, i32* %18
%269 = sext i32 %268 to i64
%270 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 %269
%271 = load i8*, i8** %270
%272 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0), i8* %271)
br label %273
273: ; preds = %267
%274 = load i32, i32* %18
%275 = add nsw i32 %274, 1
store i32 %275, i32* %18
br label %261
276: ; preds = %261
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%278 = getelementptr inbounds [15 x i8*], [15 x i8*]* %17, i64 0, i64 0
%279 = call i64 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8** %278)
%280 = icmp slt i64 %279, 0
br i1 %280, label %281, label %285
281: ; preds = %276
%282 = load i32, i32* @errno
%283 = call i8* @strerror(i32 %282)
%284 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8* %283)
br label %285
285: ; preds = %281, %276
%286 = load i8*, i8** %12
%287 = call i32 @free(i8* %286)
%288 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.26, i64 0, i64 0))
store i32 0, i32* %3
br label %289
289: ; preds = %285, %188, %173, %95, %65
%290 = load i32, i32* %3
ret i32 %290
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"bnpt:s:\00"
@EOF = global i32 0
@optarg = global i32 0
@optind = global i32 0
@.str.2 = [40 x i8] c"nv_hciatatch:Error in memory allocation\00"
@.str.3 = [6 x i8] c"/dev/\00"
@.str.4 = [39 x i8] c"nv_hciattach: tty device not specified\00"
@.str.6 = [18 x i8] c"/system/bin/bccmd\00"
@.str.7 = [3 x i8] c"-t\00"
@.str.8 = [5 x i8] c"bcsp\00"
@.str.9 = [3 x i8] c"-d\00"
@.str.10 = [7 x i8] c"psload\00"
@.str.11 = [3 x i8] c"-r\00"
@.str.12 = [25 x i8] c"/etc/bluez/bluecore6.psr\00"
@.str.13 = [15 x i8] c"BCCMD Command:\00"
@.str.14 = [4 x i8] c"%s \00"
@.str.16 = [25 x i8] c"cannot execve('%s'): %s\0A\00"
@errno = global i32 0
@.str.17 = [29 x i8] c"fork() with error:%d(%s) %d\0A\00"
@WUNTRACED = global i32 0
@.str.18 = [8 x i8] c"waitpid\00"
@.str.19 = [19 x i8] c"exited, status=%d\0A\00"
@.str.20 = [21 x i8] c"killed by signal %d\0A\00"
@.str.21 = [22 x i8] c"stopped by signal %d\0A\00"
@.str.23 = [22 x i8] c"/system/bin/hciattach\00"
@.str.24 = [20 x i8] c"hciattach command: \00"
@.str.25 = [5 x i8] c"%s \00"
@str = [51 x i8] c" Starting nv_hciattach deamon to configure BT Chip\00"
@str.27 = [47 x i8] c"Starting Bluetooth hciattach with arguments : \00"
@str.28 = [42 x i8] c"Bluetooth HCI Driver initialisation Done.\00"
@str.29 = [38 x i8] c"Using bccmd to configure the CSR Chip\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [15 x i8*]
%5 = alloca [15 x i8*]
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %23, label %11
11: ; preds = %2, %19
%12 = phi i32 [ %20, %19 ], [ %8, %2 ]
switch i32 %12, label %16 [
i32 98, label %19
i32 110, label %19
i32 112, label %19
i32 116, label %19
i32 115, label %13
]
13: ; preds = %11
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %19
16: ; preds = %11
%17 = tail call i32 (...) @usage()
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11, %11, %11, %11, %13
%20 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %11
23: ; preds = %19, %2
%24 = load i32, i32* @optind
%25 = sub nsw i32 %0, %24
%26 = icmp slt i32 %25, 2
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = icmp slt i32 %24, %0
br i1 %28, label %32, label %64
29: ; preds = %23
%30 = tail call i32 (...) @usage()
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %27, %56
%33 = phi i32 [ %60, %56 ], [ %24, %27 ]
%34 = phi i8* [ %58, %56 ], [ null, %27 ]
%35 = phi i32 [ %59, %56 ], [ 0, %27 ]
%36 = sext i32 %33 to i64
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = icmp eq i32 %35, 0
br i1 %39, label %40, label %56
40: ; preds = %32
%41 = tail call i32 @strlen(i8* %38)
%42 = add nsw i32 %41, 10
%43 = tail call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
%45 = icmp eq i64 %43, 0
br i1 %45, label %54, label %46
46: ; preds = %40
store i8 0, i8* %44
%47 = tail call i32 @strchr(i8* %38, i8 signext 47)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = tail call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = tail call i32 @strcat(i8* %44, i8* %38)
%53 = load i32, i32* @optind
br label %56
54: ; preds = %40
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %185
56: ; preds = %32, %51
%57 = phi i32 [ %33, %32 ], [ %53, %51 ]
%58 = phi i8* [ %34, %32 ], [ %44, %51 ]
%59 = add nuw nsw i32 %35, 1
%60 = add nsw i32 %57, 1
store i32 %60, i32* @optind
%61 = icmp slt i32 %60, %0
br i1 %61, label %32, label %62
62: ; preds = %56
%63 = icmp eq i8* %58, null
br i1 %63, label %64, label %66
64: ; preds = %27, %62
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %185
66: ; preds = %62
%67 = tail call i64 (...) @fork()
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %102
69: ; preds = %66
%70 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.29, i64 0, i64 0))
%71 = bitcast [15 x i8*]* %4 to i8*
%72 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 8
%73 = bitcast i8** %72 to i8*
%74 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %74
%75 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %75
%76 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8** %76
%77 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8** %77
%78 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 4
store i8* %58, i8** %78
%79 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8** %79
%80 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8** %80
%81 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 7
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i8** %81
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
br label %83
83: ; preds = %69, %83
%84 = phi i64 [ 0, %69 ], [ %87, %83 ]
%85 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %69 ], [ %89, %83 ]
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8* %85)
%87 = add nuw i64 %84, 1
%88 = getelementptr inbounds [15 x i8*], [15 x i8*]* %4, i64 0, i64 %87
%89 = load i8*, i8** %88
%90 = icmp eq i8* %89, null
br i1 %90, label %91, label %83
91: ; preds = %83
%92 = tail call i32 @putchar(i32 10)
%93 = call i64 @execv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %74)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %91
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %95, %91
%100 = call i32 @free(i8* %58)
%101 = call i32 @_exit(i32 127)
unreachable
102: ; preds = %66
%103 = icmp slt i64 %67, 0
br i1 %103, label %104, label %109
104: ; preds = %102
%105 = tail call i32 @free(i8* %58)
%106 = load i32, i32* @errno
%107 = tail call i8* @strerror(i32 %106)
%108 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0), i32 %106, i8* %107, i64 %67)
br label %185
109: ; preds = %102, %142
%110 = load i32, i32* @WUNTRACED
%111 = call i64 @waitpid(i64 %67, i32* %3, i32 %110)
%112 = icmp eq i64 %111, -1
br i1 %112, label %113, label %116
113: ; preds = %109
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0))
%115 = call i32 @free(i8* %58)
br label %185
116: ; preds = %109
%117 = load i32, i32* %3
%118 = call i64 @WIFEXITED(i32 %117)
%119 = icmp eq i64 %118, 0
%120 = load i32, i32* %3
br i1 %119, label %124, label %121
121: ; preds = %116
%122 = call i32 @WEXITSTATUS(i32 %120)
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i32 %122)
br label %138
124: ; preds = %116
%125 = call i64 @WIFSIGNALED(i32 %120)
%126 = icmp eq i64 %125, 0
%127 = load i32, i32* %3
br i1 %126, label %131, label %128
128: ; preds = %124
%129 = call i32 @WTERMSIG(i32 %127)
%130 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0), i32 %129)
br label %138
131: ; preds = %124
%132 = call i64 @WIFSTOPPED(i32 %127)
%133 = icmp eq i64 %132, 0
br i1 %133, label %138, label %134
134: ; preds = %131
%135 = load i32, i32* %3
%136 = call i32 @WSTOPSIG(i32 %135)
%137 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.21, i64 0, i64 0), i32 %136)
br label %138
138: ; preds = %121, %131, %134, %128
%139 = load i32, i32* %3
%140 = call i64 @WIFEXITED(i32 %139)
%141 = icmp eq i64 %140, 0
br i1 %141, label %142, label %146
142: ; preds = %138
%143 = load i32, i32* %3
%144 = call i64 @WIFSIGNALED(i32 %143)
%145 = icmp eq i64 %144, 0
br i1 %145, label %109, label %146
146: ; preds = %138, %142
%147 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.27, i64 0, i64 0))
%148 = bitcast [15 x i8*]* %5 to i8*
%149 = getelementptr inbounds [15 x i8*], [15 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8** %149
%150 = icmp sgt i32 %0, 1
br i1 %150, label %151, label %160
151: ; preds = %146
%152 = getelementptr inbounds [15 x i8*], [15 x i8*]* %5, i64 0, i64 1
%153 = bitcast i8** %152 to i8*
%154 = getelementptr i8*, i8** %1, i64 1
%155 = bitcast i8** %154 to i8*
%156 = add nsw i32 %0, -1
%157 = zext i32 %156 to i64
%158 = shl nuw nsw i64 %157, 3
%159 = zext i32 %0 to i64
br label %160
160: ; preds = %151, %146
%161 = phi i64 [ 1, %146 ], [ %159, %151 ]
%162 = getelementptr inbounds [15 x i8*], [15 x i8*]* %5, i64 0, i64 %161
store i8* null, i8** %162
%163 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.24, i64 0, i64 0))
%164 = load i8*, i8** %149
%165 = icmp eq i8* %164, null
br i1 %165, label %174, label %166
166: ; preds = %160, %166
%167 = phi i64 [ %170, %166 ], [ 0, %160 ]
%168 = phi i8* [ %172, %166 ], [ %164, %160 ]
%169 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0), i8* %168)
%170 = add nuw i64 %167, 1
%171 = getelementptr inbounds [15 x i8*], [15 x i8*]* %5, i64 0, i64 %170
%172 = load i8*, i8** %171
%173 = icmp eq i8* %172, null
br i1 %173, label %174, label %166
174: ; preds = %166, %160
%175 = call i32 @putchar(i32 10)
%176 = call i64 @execv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8** %149)
%177 = icmp slt i64 %176, 0
br i1 %177, label %178, label %182
178: ; preds = %174
%179 = load i32, i32* @errno
%180 = call i8* @strerror(i32 %179)
%181 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8* %180)
br label %182
182: ; preds = %178, %174
%183 = call i32 @free(i8* %58)
%184 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.28, i64 0, i64 0))
br label %185
185: ; preds = %54, %182, %113, %104, %64
%186 = phi i32 [ -1, %54 ], [ -1, %64 ], [ -1, %104 ], [ -1, %113 ], [ 0, %182 ]
ret i32 %186
}