#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int, int);
int local_cam_get_register(int, int, int, int *);
int local_cam_set_register(int, int, int, int);
int local_cam_setget_register(int, int, int, int, int *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  unsigned char outp_buf[100];
  int regval, regaddr, rc = 0;
  int i2c_fd;
  int slave_addr, wrong_addr;
  int lastregval;
  if (argc < 3) {
    printf("Usage: twi_test 0x<correct slave addr> 0x<wrong slave addr>\n "
           "Example: 0x58 for ad5280 i2c chip on bf537-lq035 board.\n");
    return 0;
  }
  slave_addr = strtol(argv[1], NULL, 16);
  wrong_addr = strtol(argv[2], NULL, 16);
  printf("slave addr: 0x%x\n", slave_addr);
  slave_addr >>= 1;
  i2c_fd = open("/dev/i2c-0", O_RDWR);
  printf("Case 1: Program with correct I2C_SLAVE "
         "address\n-----------------------------------------\n");
  if (ioctl(i2c_fd, 0x0703, slave_addr) < 0) {
    printf("Fail to set SLAVE address\n");
    return 0;
  }
  regaddr = 2;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 1;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 0;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 0x06;
  regval = 0x7f;
  rc = local_cam_set_register(i2c_fd, 1, regaddr, regval);
  if (rc) {
    printf("Fail to set data to register %d\n", regaddr);
    return 0;
  }
  sleep(1);
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Data set to register %d is wrong\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  printf("Case 2: Program with incorrect I2C_SLAVE "
         "address\n----------------------------------------\n");
  ioctl(i2c_fd, 0x0703, wrong_addr);
  sleep(1);
  regaddr = 2;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (!rc) {
    printf("Wrong addr is incorrect, read %d from reg %d\n", regval, regaddr);
    return 0;
  }
  sleep(1);
  regaddr = 0x06;
  regval = 0x20;
  rc = local_cam_set_register(i2c_fd, 1, regaddr, regval);
  if (!rc) {
    printf("Wrong addr is incorrect, write %d to reg %d\n", regval, regaddr);
    return 0;
  }
  printf("Case 3: Program with correct I2C_SLAVE "
         "address\n------------------------------------------\n");
  ioctl(i2c_fd, 0x0703, slave_addr);
  sleep(1);
  regaddr = 2;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 1;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 0;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  regaddr = 0x09;
  regval = 0x30;
  rc = local_cam_set_register(i2c_fd, 1, regaddr, regval);
  if (rc) {
    printf("Fail to set data to register %d\n", regaddr);
    return 0;
  }
  sleep(1);
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Data set to register %d is wrong\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  sleep(1);
  printf(
      "Case 4: test twi repeat\n------------------------------------------\n");
  regaddr = 2;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  lastregval = regval;
  sleep(1);
  regaddr = 0x2c;
  regval = 0;
  rc = local_cam_setget_register(i2c_fd, 1, 1, regaddr, &regval, 2);
  if (rc) {
    printf("Fail to setget data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", 2, regval);
  if (lastregval != regval) {
    printf("Fail to run twi repeat test\n");
    return 0;
  }
  sleep(1);
  regaddr = 2;
  rc = local_cam_get_register(i2c_fd, 1, regaddr, &regval);
  if (rc) {
    printf("Fail to get data from register %d\n", regaddr);
    return 0;
  }
  printf("reg %d = 0x%x\n", regaddr, regval);
  close(i2c_fd);
  printf("TWI I2C test .... [PASS]\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x8c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d7 <main+0x47>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x94(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x90(%rbp)
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x90(%rbp),%edi
mov    -0x94(%rbp),%edx
mov    $0x703,%esi
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1295 <main+0x105>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
movl   $0x2,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     12ef <main+0x15f>
mov    -0x88(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x1,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     136d <main+0x1dd>
mov    -0x88(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     13eb <main+0x25b>
mov    -0x88(%rbp),%esi
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x6,-0x88(%rbp)
movl   $0x7f,-0x84(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    -0x84(%rbp),%ecx
mov    $0x1,%esi
call   10b0 <local_cam_set_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     1472 <main+0x2e2>
mov    -0x88(%rbp),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     14cc <main+0x33c>
mov    -0x88(%rbp),%esi
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xc4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x90(%rbp),%edi
mov    -0x98(%rbp),%edx
mov    $0x703,%esi
call   1060 <ioctl@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x2,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jne    1574 <main+0x3e4>
mov    -0x84(%rbp),%esi
mov    -0x88(%rbp),%edx
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x6,-0x88(%rbp)
movl   $0x20,-0x84(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    -0x84(%rbp),%ecx
mov    $0x1,%esi
call   10b0 <local_cam_set_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jne    15e7 <main+0x457>
mov    -0x84(%rbp),%esi
mov    -0x88(%rbp),%edx
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
lea    0xc45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x90(%rbp),%edi
mov    -0x94(%rbp),%edx
mov    $0x703,%esi
call   1060 <ioctl@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x2,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     166f <main+0x4df>
mov    -0x88(%rbp),%esi
lea    0xaac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xaa9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x1,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     16ed <main+0x55d>
mov    -0x88(%rbp),%esi
lea    0xa2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0xa2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     176b <main+0x5db>
mov    -0x88(%rbp),%esi
lea    0x9b0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0x9ad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x9,-0x88(%rbp)
movl   $0x30,-0x84(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    -0x84(%rbp),%ecx
mov    $0x1,%esi
call   10b0 <local_cam_set_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     17f2 <main+0x662>
mov    -0x88(%rbp),%esi
lea    0x95b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     184c <main+0x6bc>
mov    -0x88(%rbp),%esi
lea    0x922(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0x8cc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xa17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     18d8 <main+0x748>
mov    -0x88(%rbp),%esi
lea    0x843(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0x840(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x2c,-0x88(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%ecx
mov    $0x1,%edx
lea    -0x84(%rbp),%r8
mov    $0x2,%r9d
mov    %edx,%esi
call   1050 <local_cam_setget_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     1974 <main+0x7e4>
mov    -0x88(%rbp),%esi
lea    0x971(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x84(%rbp),%edx
lea    0x7aa(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c(%rbp),%eax
cmp    -0x84(%rbp),%eax
je     19b9 <main+0x829>
lea    0x952(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x2,-0x88(%rbp)
mov    -0x90(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    $0x1,%esi
lea    -0x84(%rbp),%rcx
call   1030 <local_cam_get_register@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     1a1d <main+0x88d>
mov    -0x88(%rbp),%esi
lea    0x6fe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a57 <main+0x8c7>
mov    -0x88(%rbp),%esi
mov    -0x84(%rbp),%edx
lea    0x6fb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x90(%rbp),%edi
call   1070 <close@plt>
lea    0x8cc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jg     11b9 <main+0x19>
lea    0x10fe(%rip),%rdi
jmp    125b <main+0xbb>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,%r14d
lea    0xe18(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
sar    %ebp
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
lea    0xf02(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x703,%esi
mov    %ebp,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1254 <main+0xb4>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     1265 <main+0xc5>
lea    0xdd3(%rip),%rdi
mov    $0x2,%esi
jmp    136d <main+0x1cd>
lea    0x103d(%rip),%rdi
call   1040 <puts@plt>
jmp    1374 <main+0x1d4>
mov    0xc(%rsp),%edx
lea    0xdd0(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     12b1 <main+0x111>
lea    0xd76(%rip),%rdi
mov    $0x1,%esi
jmp    136d <main+0x1cd>
mov    0xc(%rsp),%edx
lea    0xd84(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     12f4 <main+0x154>
lea    0xd2d(%rip),%rdi
xor    %esi,%esi
jmp    136d <main+0x1cd>
mov    0xc(%rsp),%edx
lea    0xd41(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
movl   $0x7f,0xc(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x6,%edx
mov    $0x7f,%ecx
call   10c0 <local_cam_set_register@plt>
test   %eax,%eax
je     133d <main+0x19d>
lea    0xd14(%rip),%rdi
jmp    1368 <main+0x1c8>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     137f <main+0x1df>
lea    0xd08(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0xc(%rsp),%edx
lea    0xcb6(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x703,%esi
mov    %r14d,%edx
call   1070 <ioctl@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     1517 <main+0x377>
mov    $0x1,%edi
call   10b0 <sleep@plt>
movl   $0x20,0xc(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x6,%edx
mov    $0x20,%ecx
call   10c0 <local_cam_set_register@plt>
test   %eax,%eax
je     1529 <main+0x389>
lea    0xdb6(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x703,%esi
mov    %ebp,%edx
call   1070 <ioctl@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
jne    1243 <main+0xa3>
mov    0xc(%rsp),%edx
lea    0xbea(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
jne    12a0 <main+0x100>
mov    0xc(%rsp),%edx
lea    0xbab(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
jne    12e9 <main+0x149>
mov    0xc(%rsp),%edx
lea    0xb6f(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
movl   $0x30,0xc(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x9,%edx
mov    $0x30,%ecx
call   10c0 <local_cam_set_register@plt>
test   %eax,%eax
je     1545 <main+0x3a5>
lea    0xb42(%rip),%rdi
mov    $0x9,%esi
jmp    136d <main+0x1cd>
mov    0xc(%rsp),%esi
lea    0xb70(%rip),%rdi
mov    $0x2,%edx
jmp    1539 <main+0x399>
mov    0xc(%rsp),%esi
lea    0xb8c(%rip),%rdi
mov    $0x6,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1374 <main+0x1d4>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x9,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
je     157a <main+0x3da>
lea    0xb00(%rip),%rdi
mov    $0x9,%esi
jmp    136d <main+0x1cd>
mov    0xc(%rsp),%edx
lea    0xabb(%rip),%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc7e(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
jne    1243 <main+0xa3>
mov    0xc(%rsp),%edx
lea    0xa70(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ebp
mov    $0x1,%edi
call   10b0 <sleep@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r8
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x2c,%ecx
mov    $0x2,%r9d
call   1060 <local_cam_setget_register@plt>
test   %eax,%eax
je     1628 <main+0x488>
lea    0xacf(%rip),%rdi
mov    $0x2c,%esi
jmp    136d <main+0x1cd>
mov    0xc(%rsp),%edx
lea    0xa0d(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    0xc(%rsp),%ebp
jne    1697 <main+0x4f7>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <local_cam_get_register@plt>
test   %eax,%eax
jne    1243 <main+0xa3>
mov    0xc(%rsp),%edx
lea    0x9c8(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xbd1(%rip),%rdi
jmp    125b <main+0xbb>
lea    0xbde(%rip),%rdi
jmp    125b <main+0xbb>

LLVM IR (-O0):
@.str = [118 x i8] c"Usage: twi_test 0x<correct slave addr> 0x<wrong slave addr>\0A Example: 0x58 for ad5280 i2c chip on bf537-lq035 board.\0A\00"
@.str.1 = [18 x i8] c"slave addr: 0x%x\0A\00"
@.str.2 = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.3 = [90 x i8] c"Case 1: Program with correct I2C_SLAVE address\0A-----------------------------------------\0A\00"
@.str.4 = [27 x i8] c"Fail to set SLAVE address\0A\00"
@.str.5 = [35 x i8] c"Fail to get data from register %d\0A\00"
@.str.6 = [15 x i8] c"reg %d = 0x%x\0A\00"
@.str.7 = [33 x i8] c"Fail to set data to register %d\0A\00"
@.str.8 = [34 x i8] c"Data set to register %d is wrong\0A\00"
@.str.9 = [91 x i8] c"Case 2: Program with incorrect I2C_SLAVE address\0A----------------------------------------\0A\00"
@.str.10 = [46 x i8] c"Wrong addr is incorrect, read %d from reg %d\0A\00"
@.str.11 = [45 x i8] c"Wrong addr is incorrect, write %d to reg %d\0A\00"
@.str.12 = [91 x i8] c"Case 3: Program with correct I2C_SLAVE address\0A------------------------------------------\0A\00"
@.str.13 = [68 x i8] c"Case 4: test twi repeat\0A------------------------------------------\0A\00"
@.str.14 = [38 x i8] c"Fail to setget data from register %d\0A\00"
@.str.15 = [29 x i8] c"Fail to run twi repeat test\0A\00"
@.str.16 = [26 x i8] c"TWI I2C test .... [PASS]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %246
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtol(i8* %21, i32* null, i32 16)
store i32 %22, i32* %11
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strtol(i8* %25, i32* null, i32 16)
store i32 %26, i32* %12
%27 = load i32, i32* %11
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %11
%30 = ashr i32 %29, 1
store i32 %30, i32* %11
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %31)
store i32 %32, i32* %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* %10
%35 = load i32, i32* %11
%36 = call i64 @ioctl(i32 %34, i32 1795, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %18
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %246
40: ; preds = %18
store i32 2, i32* %8
%41 = load i32, i32* %10
%42 = load i32, i32* %8
%43 = call i32 @local_cam_get_register(i32 %41, i32 1, i32 %42, i32* %7)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %47)
store i32 0, i32* %3
br label %246
49: ; preds = %40
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %51)
%53 = call i32 @sleep(i32 1)
store i32 1, i32* %8
%54 = load i32, i32* %10
%55 = load i32, i32* %8
%56 = call i32 @local_cam_get_register(i32 %54, i32 1, i32 %55, i32* %7)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %49
%60 = load i32, i32* %8
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %60)
store i32 0, i32* %3
br label %246
62: ; preds = %49
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %63, i32 %64)
%66 = call i32 @sleep(i32 1)
store i32 0, i32* %8
%67 = load i32, i32* %10
%68 = load i32, i32* %8
%69 = call i32 @local_cam_get_register(i32 %67, i32 1, i32 %68, i32* %7)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %62
%73 = load i32, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %73)
store i32 0, i32* %3
br label %246
75: ; preds = %62
%76 = load i32, i32* %8
%77 = load i32, i32* %7
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %76, i32 %77)
%79 = call i32 @sleep(i32 1)
store i32 6, i32* %8
store i32 127, i32* %7
%80 = load i32, i32* %10
%81 = load i32, i32* %8
%82 = load i32, i32* %7
%83 = call i32 @local_cam_set_register(i32 %80, i32 1, i32 %81, i32 %82)
store i32 %83, i32* %9
%84 = load i32, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %75
%87 = load i32, i32* %8
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %87)
store i32 0, i32* %3
br label %246
89: ; preds = %75
%90 = call i32 @sleep(i32 1)
%91 = load i32, i32* %10
%92 = load i32, i32* %8
%93 = call i32 @local_cam_get_register(i32 %91, i32 1, i32 %92, i32* %7)
store i32 %93, i32* %9
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %89
%97 = load i32, i32* %8
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %97)
store i32 0, i32* %3
br label %246
99: ; preds = %89
%100 = load i32, i32* %8
%101 = load i32, i32* %7
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %100, i32 %101)
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.9, i64 0, i64 0))
%104 = load i32, i32* %10
%105 = load i32, i32* %12
%106 = call i64 @ioctl(i32 %104, i32 1795, i32 %105)
%107 = call i32 @sleep(i32 1)
store i32 2, i32* %8
%108 = load i32, i32* %10
%109 = load i32, i32* %8
%110 = call i32 @local_cam_get_register(i32 %108, i32 1, i32 %109, i32* %7)
store i32 %110, i32* %9
%111 = load i32, i32* %9
%112 = icmp ne i32 %111, 0
br i1 %112, label %117, label %113
113: ; preds = %99
%114 = load i32, i32* %7
%115 = load i32, i32* %8
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i32 %114, i32 %115)
store i32 0, i32* %3
br label %246
117: ; preds = %99
%118 = call i32 @sleep(i32 1)
store i32 6, i32* %8
store i32 32, i32* %7
%119 = load i32, i32* %10
%120 = load i32, i32* %8
%121 = load i32, i32* %7
%122 = call i32 @local_cam_set_register(i32 %119, i32 1, i32 %120, i32 %121)
store i32 %122, i32* %9
%123 = load i32, i32* %9
%124 = icmp ne i32 %123, 0
br i1 %124, label %129, label %125
125: ; preds = %117
%126 = load i32, i32* %7
%127 = load i32, i32* %8
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0), i32 %126, i32 %127)
store i32 0, i32* %3
br label %246
129: ; preds = %117
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.12, i64 0, i64 0))
%131 = load i32, i32* %10
%132 = load i32, i32* %11
%133 = call i64 @ioctl(i32 %131, i32 1795, i32 %132)
%134 = call i32 @sleep(i32 1)
store i32 2, i32* %8
%135 = load i32, i32* %10
%136 = load i32, i32* %8
%137 = call i32 @local_cam_get_register(i32 %135, i32 1, i32 %136, i32* %7)
store i32 %137, i32* %9
%138 = load i32, i32* %9
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %129
%141 = load i32, i32* %8
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %141)
store i32 0, i32* %3
br label %246
143: ; preds = %129
%144 = load i32, i32* %8
%145 = load i32, i32* %7
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %144, i32 %145)
%147 = call i32 @sleep(i32 1)
store i32 1, i32* %8
%148 = load i32, i32* %10
%149 = load i32, i32* %8
%150 = call i32 @local_cam_get_register(i32 %148, i32 1, i32 %149, i32* %7)
store i32 %150, i32* %9
%151 = load i32, i32* %9
%152 = icmp ne i32 %151, 0
br i1 %152, label %153, label %156
153: ; preds = %143
%154 = load i32, i32* %8
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %154)
store i32 0, i32* %3
br label %246
156: ; preds = %143
%157 = load i32, i32* %8
%158 = load i32, i32* %7
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %157, i32 %158)
%160 = call i32 @sleep(i32 1)
store i32 0, i32* %8
%161 = load i32, i32* %10
%162 = load i32, i32* %8
%163 = call i32 @local_cam_get_register(i32 %161, i32 1, i32 %162, i32* %7)
store i32 %163, i32* %9
%164 = load i32, i32* %9
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %169
166: ; preds = %156
%167 = load i32, i32* %8
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %167)
store i32 0, i32* %3
br label %246
169: ; preds = %156
%170 = load i32, i32* %8
%171 = load i32, i32* %7
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %170, i32 %171)
%173 = call i32 @sleep(i32 1)
store i32 9, i32* %8
store i32 48, i32* %7
%174 = load i32, i32* %10
%175 = load i32, i32* %8
%176 = load i32, i32* %7
%177 = call i32 @local_cam_set_register(i32 %174, i32 1, i32 %175, i32 %176)
store i32 %177, i32* %9
%178 = load i32, i32* %9
%179 = icmp ne i32 %178, 0
br i1 %179, label %180, label %183
180: ; preds = %169
%181 = load i32, i32* %8
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %181)
store i32 0, i32* %3
br label %246
183: ; preds = %169
%184 = call i32 @sleep(i32 1)
%185 = load i32, i32* %10
%186 = load i32, i32* %8
%187 = call i32 @local_cam_get_register(i32 %185, i32 1, i32 %186, i32* %7)
store i32 %187, i32* %9
%188 = load i32, i32* %9
%189 = icmp ne i32 %188, 0
br i1 %189, label %190, label %193
190: ; preds = %183
%191 = load i32, i32* %8
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %191)
store i32 0, i32* %3
br label %246
193: ; preds = %183
%194 = load i32, i32* %8
%195 = load i32, i32* %7
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %194, i32 %195)
%197 = call i32 @sleep(i32 1)
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.13, i64 0, i64 0))
store i32 2, i32* %8
%199 = load i32, i32* %10
%200 = load i32, i32* %8
%201 = call i32 @local_cam_get_register(i32 %199, i32 1, i32 %200, i32* %7)
store i32 %201, i32* %9
%202 = load i32, i32* %9
%203 = icmp ne i32 %202, 0
br i1 %203, label %204, label %207
204: ; preds = %193
%205 = load i32, i32* %8
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %205)
store i32 0, i32* %3
br label %246
207: ; preds = %193
%208 = load i32, i32* %8
%209 = load i32, i32* %7
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %208, i32 %209)
%211 = load i32, i32* %7
store i32 %211, i32* %13
%212 = call i32 @sleep(i32 1)
store i32 44, i32* %8
store i32 0, i32* %7
%213 = load i32, i32* %10
%214 = load i32, i32* %8
%215 = call i32 @local_cam_setget_register(i32 %213, i32 1, i32 1, i32 %214, i32* %7, i32 2)
store i32 %215, i32* %9
%216 = load i32, i32* %9
%217 = icmp ne i32 %216, 0
br i1 %217, label %218, label %221
218: ; preds = %207
%219 = load i32, i32* %8
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0), i32 %219)
store i32 0, i32* %3
br label %246
221: ; preds = %207
%222 = load i32, i32* %7
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %222)
%224 = load i32, i32* %13
%225 = load i32, i32* %7
%226 = icmp ne i32 %224, %225
br i1 %226, label %227, label %229
227: ; preds = %221
%228 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %3
br label %246
229: ; preds = %221
%230 = call i32 @sleep(i32 1)
store i32 2, i32* %8
%231 = load i32, i32* %10
%232 = load i32, i32* %8
%233 = call i32 @local_cam_get_register(i32 %231, i32 1, i32 %232, i32* %7)
store i32 %233, i32* %9
%234 = load i32, i32* %9
%235 = icmp ne i32 %234, 0
br i1 %235, label %236, label %239
236: ; preds = %229
%237 = load i32, i32* %8
%238 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %237)
store i32 0, i32* %3
br label %246
239: ; preds = %229
%240 = load i32, i32* %8
%241 = load i32, i32* %7
%242 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %240, i32 %241)
%243 = load i32, i32* %10
%244 = call i32 @close(i32 %243)
%245 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %3
br label %246
246: ; preds = %239, %236, %227, %218, %204, %190, %180, %166, %153, %140, %125, %113, %96, %86, %72, %59, %46, %38, %16
%247 = load i32, i32* %3
ret i32 %247
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"slave addr: 0x%x\0A\00"
@.str.2 = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.5 = [35 x i8] c"Fail to get data from register %d\0A\00"
@.str.6 = [15 x i8] c"reg %d = 0x%x\0A\00"
@.str.7 = [33 x i8] c"Fail to set data to register %d\0A\00"
@.str.8 = [34 x i8] c"Data set to register %d is wrong\0A\00"
@.str.10 = [46 x i8] c"Wrong addr is incorrect, read %d from reg %d\0A\00"
@.str.11 = [45 x i8] c"Wrong addr is incorrect, write %d to reg %d\0A\00"
@.str.14 = [38 x i8] c"Fail to setget data from register %d\0A\00"
@str = [89 x i8] c"Case 1: Program with correct I2C_SLAVE address\0A-----------------------------------------\00"
@str.17 = [90 x i8] c"Case 2: Program with incorrect I2C_SLAVE address\0A----------------------------------------\00"
@str.18 = [90 x i8] c"Case 3: Program with correct I2C_SLAVE address\0A------------------------------------------\00"
@str.19 = [67 x i8] c"Case 4: test twi repeat\0A------------------------------------------\00"
@str.20 = [25 x i8] c"TWI I2C test .... [PASS]\00"
@str.21 = [28 x i8] c"Fail to run twi repeat test\00"
@str.22 = [26 x i8] c"Fail to set SLAVE address\00"
@str.23 = [117 x i8] c"Usage: twi_test 0x<correct slave addr> 0x<wrong slave addr>\0A Example: 0x58 for ad5280 i2c chip on bf537-lq035 board.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([117 x i8], [117 x i8]* @str.23, i64 0, i64 0))
br label %151
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strtol(i8* nocapture %10, i32* null, i32 16)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strtol(i8* nocapture %13, i32* null, i32 16)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%16 = ashr i32 %11, 1
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @str, i64 0, i64 0))
%20 = tail call i64 @ioctl(i32 %18, i32 1795, i32 %16)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.22, i64 0, i64 0))
br label %151
24: ; preds = %8
%25 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 2, i32* %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %151
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %30)
%32 = call i32 @sleep(i32 1)
%33 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 1, i32* %3)
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %151
37: ; preds = %29
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 %38)
%40 = call i32 @sleep(i32 1)
%41 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 0, i32* %3)
%42 = icmp eq i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %151
45: ; preds = %37
%46 = load i32, i32* %3
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 0, i32 %46)
%48 = call i32 @sleep(i32 1)
store i32 127, i32* %3
%49 = call i32 @local_cam_set_register(i32 %18, i32 1, i32 6, i32 127)
%50 = icmp eq i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 6)
br label %151
53: ; preds = %45
%54 = call i32 @sleep(i32 1)
%55 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 6, i32* %3)
%56 = icmp eq i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 6)
br label %151
59: ; preds = %53
%60 = load i32, i32* %3
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 6, i32 %60)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.17, i64 0, i64 0))
%63 = call i64 @ioctl(i32 %18, i32 1795, i32 %14)
%64 = call i32 @sleep(i32 1)
%65 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 2, i32* %3)
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %59
%68 = load i32, i32* %3
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i32 %68, i32 2)
br label %151
70: ; preds = %59
%71 = call i32 @sleep(i32 1)
store i32 32, i32* %3
%72 = call i32 @local_cam_set_register(i32 %18, i32 1, i32 6, i32 32)
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i32, i32* %3
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0), i32 %75, i32 6)
br label %151
77: ; preds = %70
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.18, i64 0, i64 0))
%79 = call i64 @ioctl(i32 %18, i32 1795, i32 %16)
%80 = call i32 @sleep(i32 1)
%81 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 2, i32* %3)
%82 = icmp eq i32 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %77
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %151
85: ; preds = %77
%86 = load i32, i32* %3
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %86)
%88 = call i32 @sleep(i32 1)
%89 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 1, i32* %3)
%90 = icmp eq i32 %89, 0
br i1 %90, label %93, label %91
91: ; preds = %85
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %151
93: ; preds = %85
%94 = load i32, i32* %3
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 %94)
%96 = call i32 @sleep(i32 1)
%97 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 0, i32* %3)
%98 = icmp eq i32 %97, 0
br i1 %98, label %101, label %99
99: ; preds = %93
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %151
101: ; preds = %93
%102 = load i32, i32* %3
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 0, i32 %102)
%104 = call i32 @sleep(i32 1)
store i32 48, i32* %3
%105 = call i32 @local_cam_set_register(i32 %18, i32 1, i32 9, i32 48)
%106 = icmp eq i32 %105, 0
br i1 %106, label %109, label %107
107: ; preds = %101
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 9)
br label %151
109: ; preds = %101
%110 = call i32 @sleep(i32 1)
%111 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 9, i32* %3)
%112 = icmp eq i32 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %109
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 9)
br label %151
115: ; preds = %109
%116 = load i32, i32* %3
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 9, i32 %116)
%118 = call i32 @sleep(i32 1)
%119 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.19, i64 0, i64 0))
%120 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 2, i32* %3)
%121 = icmp eq i32 %120, 0
br i1 %121, label %124, label %122
122: ; preds = %115
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %151
124: ; preds = %115
%125 = load i32, i32* %3
%126 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %125)
%127 = load i32, i32* %3
%128 = call i32 @sleep(i32 1)
store i32 0, i32* %3
%129 = call i32 @local_cam_setget_register(i32 %18, i32 1, i32 1, i32 44, i32* %3, i32 2)
%130 = icmp eq i32 %129, 0
br i1 %130, label %133, label %131
131: ; preds = %124
%132 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0), i32 44)
br label %151
133: ; preds = %124
%134 = load i32, i32* %3
%135 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %134)
%136 = load i32, i32* %3
%137 = icmp eq i32 %127, %136
br i1 %137, label %140, label %138
138: ; preds = %133
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.21, i64 0, i64 0))
br label %151
140: ; preds = %133
%141 = call i32 @sleep(i32 1)
%142 = call i32 @local_cam_get_register(i32 %18, i32 1, i32 2, i32* %3)
%143 = icmp eq i32 %142, 0
br i1 %143, label %146, label %144
144: ; preds = %140
%145 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %151
146: ; preds = %140
%147 = load i32, i32* %3
%148 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 2, i32 %147)
%149 = call i32 @close(i32 %18)
%150 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.20, i64 0, i64 0))
br label %151
151: ; preds = %146, %144, %138, %131, %122, %113, %107, %99, %91, %83, %74, %67, %57, %51, %43, %35, %27, %22, %6
ret i32 0
}