#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 BUS;
int I2CWrapperOpen(int, int);
int /*<<< orphan*/ I2CWrapperSlaveAddress(int, int);
int /*<<< orphan*/ I2CWrapperWriteByte(int, int, int);
int /*<<< orphan*/ I2CWrapperWriteWord(int, int, int);
int /*<<< orphan*/ ValidateAddress(int);
int /*<<< orphan*/ ValidateDevice(int);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strstr(char *, char *);
int strtoul(char *, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int i2c_handle;
  int CurrentAddress;
  int NewAddress;
  int rcode;
  const BUS = 1;
  if (argc != 3) {
    printf("Usage:\n         A2DAdress  [Current Address]  [New Address]\n");
    return (-1);
  }
  if (strstr(argv[1], "0x") == NULL)
    CurrentAddress = atoi(argv[1]);
  else
    CurrentAddress = strtoul(argv[1], 0, 16);
  if (strstr(argv[1], "0x") == NULL)
    NewAddress = atoi(argv[2]);
  else
    NewAddress = strtoul(argv[2], 0, 16);
  if (!ValidateAddress(CurrentAddress)) {
    fprintf(stderr, "Current I2C Address=%X is  invalid!\n", CurrentAddress);
    return (-1);
  }
  if (!ValidateAddress(CurrentAddress)) {
    fprintf(stderr, "New I2C Address=%X is  invalid!\n", CurrentAddress);
    return (-1);
  }
  i2c_handle = I2CWrapperOpen(BUS, CurrentAddress);
  if (i2c_handle < 0) {
    fprintf(stderr, "Unable to open I2C smbus\n");
    return (-1);
  }
  if (!ValidateDevice(i2c_handle)) {
    fprintf(stderr, "Slave device bot found at  %02X is invalid",
            CurrentAddress);
    return (-1);
  }
  I2CWrapperWriteByte(i2c_handle, 5, NewAddress);
  I2CWrapperWriteWord(i2c_handle, 9, 0xAA55);
  sleep(1);
  I2CWrapperSlaveAddress(i2c_handle, NewAddress);
  if (!ValidateDevice(i2c_handle)) {
    fprintf(stderr, "Unable to find new slave Address at %02X", NewAddress);
    return (-1);
  }
  printf(" Device at %X is now at %X\n", CurrentAddress, NewAddress);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1201 <main+0x41>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2d(%rip),%rsi
call   10e0 <strstr@plt>
cmp    $0x0,%rax
jne    1234 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    124b <main+0x8b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde3(%rip),%rsi
call   10e0 <strstr@plt>
cmp    $0x0,%rax
jne    127e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1295 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <ValidateAddress@plt>
cmp    $0x0,%eax
jne    12cc <main+0x10c>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x18(%rbp),%edi
call   1060 <ValidateAddress@plt>
cmp    $0x0,%eax
jne    1303 <main+0x143>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x18(%rbp),%esi
mov    $0x1,%edi
call   1080 <I2CWrapperOpen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1340 <main+0x180>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x14(%rbp),%edi
call   1040 <ValidateDevice@plt>
cmp    $0x0,%eax
jne    1377 <main+0x1b7>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x5,%esi
call   10c0 <I2CWrapperWriteByte@plt>
mov    -0x14(%rbp),%edi
mov    $0x9,%esi
mov    $0xaa55,%edx
call   1030 <I2CWrapperWriteWord@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <I2CWrapperSlaveAddress@plt>
mov    -0x14(%rbp),%edi
call   1040 <ValidateDevice@plt>
cmp    $0x0,%eax
jne    13e5 <main+0x225>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xcf9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1400 <main+0x240>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    120f <main+0x3f>
mov    %rsi,%rbp
mov    0x8(%rsi),%rbx
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strstr@plt>
test   %rax,%rax
je     1220 <main+0x50>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r15d
mov    0x8(%rbp),%rbx
jmp    122b <main+0x5b>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
jmp    1351 <main+0x181>
mov    %rbx,%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
lea    0xdce(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strstr@plt>
mov    0x10(%rbp),%rdi
test   %rax,%rax
je     1251 <main+0x81>
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
jmp    1256 <main+0x86>
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    %r15d,%edi
call   1070 <ValidateAddress@plt>
test   %eax,%eax
je     12fa <main+0x12a>
mov    %r15d,%edi
call   1070 <ValidateAddress@plt>
test   %eax,%eax
je     130c <main+0x13c>
mov    $0x1,%edi
mov    %r15d,%esi
call   1090 <I2CWrapperOpen@plt>
test   %eax,%eax
js     131e <main+0x14e>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <ValidateDevice@plt>
test   %eax,%eax
je     1337 <main+0x167>
mov    %ebp,%edi
mov    $0x5,%esi
mov    %r14d,%edx
call   10d0 <I2CWrapperWriteByte@plt>
mov    %ebp,%edi
mov    $0x9,%esi
mov    $0xaa55,%edx
call   1040 <I2CWrapperWriteWord@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1080 <I2CWrapperSlaveAddress@plt>
mov    %ebp,%edi
call   1050 <ValidateDevice@plt>
test   %eax,%eax
je     1363 <main+0x193>
lea    0xdce(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1356 <main+0x186>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
jmp    1347 <main+0x177>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd0c(%rip),%rsi
jmp    1347 <main+0x177>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1351 <main+0x181>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
mov    %r14d,%edx
jmp    134a <main+0x17a>

LLVM IR (-O0):
@.str = [61 x i8] c"Usage:\0A A2DAdress [Current Address] [New Address]\0A\00"
@.str.1 = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Current I2C Address=%X is invalid!\0A\00"
@.str.3 = [33 x i8] c"New I2C Address=%X is invalid!\0A\00"
@.str.4 = [26 x i8] c"Unable to open I2C smbus\0A\00"
@.str.5 = [43 x i8] c"Slave device bot found at %02X is invalid\00"
@.str.6 = [41 x i8] c"Unable to find new slave Address at %02X\00"
@.str.7 = [28 x i8] c" Device at %X is now at %X\0A\00"
@BUS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %100
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @strstr(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
br label %31
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strtoul(i8* %29, i32 0, i32 16)
store i32 %30, i32* %7
br label %31
31: ; preds = %26, %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32* @strstr(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %8
br label %47
42: ; preds = %31
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strtoul(i8* %45, i32 0, i32 16)
store i32 %46, i32* %8
br label %47
47: ; preds = %42, %37
%48 = load i32, i32* %7
%49 = call i32 @ValidateAddress(i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = load i32, i32* %7
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %53)
store i32 -1, i32* %3
br label %100
55: ; preds = %47
%56 = load i32, i32* %7
%57 = call i32 @ValidateAddress(i32 %56)
%58 = icmp ne i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i32, i32* %7
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %61)
store i32 -1, i32* %3
br label %100
63: ; preds = %55
%64 = load i32, i32* %7
%65 = call i32 @I2CWrapperOpen(i32 1, i32 %64)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %100
71: ; preds = %63
%72 = load i32, i32* %6
%73 = call i32 @ValidateDevice(i32 %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %79, label %75
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i32, i32* %7
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %77)
store i32 -1, i32* %3
br label %100
79: ; preds = %71
%80 = load i32, i32* %6
%81 = load i32, i32* %8
%82 = call i32 @I2CWrapperWriteByte(i32 %80, i32 5, i32 %81)
%83 = load i32, i32* %6
%84 = call i32 @I2CWrapperWriteWord(i32 %83, i32 9, i32 43605)
%85 = call i32 @sleep(i32 1)
%86 = load i32, i32* %6
%87 = load i32, i32* %8
%88 = call i32 @I2CWrapperSlaveAddress(i32 %86, i32 %87)
%89 = load i32, i32* %6
%90 = call i32 @ValidateDevice(i32 %89)
%91 = icmp ne i32 %90, 0
br i1 %91, label %96, label %92
92: ; preds = %79
%93 = load i32, i32* @stderr
%94 = load i32, i32* %8
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %94)
store i32 -1, i32* %3
br label %100
96: ; preds = %79
%97 = load i32, i32* %7
%98 = load i32, i32* %8
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %97, i32 %98)
store i32 0, i32* %3
br label %100
100: ; preds = %96, %92, %75, %68, %59, %51, %13
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Current I2C Address=%X is invalid!\0A\00"
@.str.3 = [33 x i8] c"New I2C Address=%X is invalid!\0A\00"
@.str.4 = [26 x i8] c"Unable to open I2C smbus\0A\00"
@.str.5 = [43 x i8] c"Slave device bot found at %02X is invalid\00"
@.str.6 = [41 x i8] c"Unable to find new slave Address at %02X\00"
@.str.7 = [28 x i8] c" Device at %X is now at %X\0A\00"
@BUS = global i32 0
@str = [60 x i8] c"Usage:\0A A2DAdress [Current Address] [New Address]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %64
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @atoi(i8* %8)
br label %16
13: ; preds = %6
%14 = tail call i32 @strtoul(i8* %8, i32 0, i32 16)
%15 = load i8*, i8** %7
br label %16
16: ; preds = %13, %11
%17 = phi i8* [ %8, %11 ], [ %15, %13 ]
%18 = phi i32 [ %12, %11 ], [ %14, %13 ]
%19 = tail call i32* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
br i1 %20, label %23, label %25
23: ; preds = %16
%24 = tail call i32 @atoi(i8* %22)
br label %27
25: ; preds = %16
%26 = tail call i32 @strtoul(i8* %22, i32 0, i32 16)
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ %24, %23 ], [ %26, %25 ]
%29 = tail call i32 @ValidateAddress(i32 %18)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %64
34: ; preds = %27
%35 = tail call i32 @ValidateAddress(i32 %18)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %64
40: ; preds = %34
%41 = tail call i32 @I2CWrapperOpen(i32 1, i32 %18)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %64
46: ; preds = %40
%47 = tail call i32 @ValidateDevice(i32 %41)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %64
52: ; preds = %46
%53 = tail call i32 @I2CWrapperWriteByte(i32 %41, i32 5, i32 %28)
%54 = tail call i32 @I2CWrapperWriteWord(i32 %41, i32 9, i32 43605)
%55 = tail call i32 @sleep(i32 1)
%56 = tail call i32 @I2CWrapperSlaveAddress(i32 %41, i32 %28)
%57 = tail call i32 @ValidateDevice(i32 %41)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %28)
br label %64
62: ; preds = %52
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %18, i32 %28)
br label %64
64: ; preds = %62, %59, %49, %43, %37, %31, %4
%65 = phi i32 [ -1, %4 ], [ -1, %43 ], [ 0, %62 ], [ -1, %59 ], [ -1, %49 ], [ -1, %37 ], [ -1, %31 ]
ret i32 %65
}