#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ i2c_deinit();
int /*<<< orphan*/ i2c_getopt(int, char **);
int /*<<< orphan*/ i2c_hw_start();
int /*<<< orphan*/ i2c_hw_stop();
int /*<<< orphan*/ i2c_hw_tx_byte(int);
int /*<<< orphan*/ i2c_init();
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i, address, cmdbuf;
  char *conv_err;
  i2c_getopt(argc, argv);
  if (argc < 3) {
    fputs("Usage: i2cset <address> <data ...>", stderr);
    return 1;
  }
  address = strtol(argv[1], &conv_err, 0);
  if (conv_err && *conv_err) {
    fprintf(stderr, "Conversion error at '%s'\n", conv_err);
    return 2;
  }
  i2c_init();
  i2c_hw_start();
  if (!i2c_hw_tx_byte(address << 1)) {
    fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address);
    i2c_hw_stop();
    i2c_deinit();
    return 3;
  }
  for (i = 2; i < argc; i++) {
    cmdbuf = strtol(argv[i], &conv_err, 0);
    if (conv_err && *conv_err) {
      fprintf(stderr, "write command: conversion error at '%s'\n", conv_err);
      i2c_hw_stop();
      i2c_deinit();
      return 2;
    }
    if (!i2c_hw_tx_byte(cmdbuf)) {
      fprintf(stderr, "Received NAK after byte %d (0x%02x)\n", i - 1, cmdbuf);
      i2c_hw_stop();
      i2c_deinit();
      return 4;
    }
  }
  i2c_hw_stop();
  i2c_deinit();
  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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <i2c_getopt@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11dd <main+0x4d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    137b <main+0x1eb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1235 <main+0xa5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1235 <main+0xa5>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    137b <main+0x1eb>
mov    $0x0,%al
call   1030 <i2c_init@plt>
mov    $0x0,%al
call   10a0 <i2c_hw_start@plt>
mov    -0x18(%rbp),%edi
shl    $0x1,%edi
call   1090 <i2c_hw_tx_byte@plt>
cmp    $0x0,%eax
jne    128b <main+0xfb>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <i2c_hw_stop@plt>
mov    $0x0,%al
call   10b0 <i2c_deinit@plt>
movl   $0x3,-0x4(%rbp)
jmp    137b <main+0x1eb>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1366 <main+0x1d6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1308 <main+0x178>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1308 <main+0x178>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd80(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <i2c_hw_stop@plt>
mov    $0x0,%al
call   10b0 <i2c_deinit@plt>
movl   $0x2,-0x4(%rbp)
jmp    137b <main+0x1eb>
mov    -0x1c(%rbp),%edi
call   1090 <i2c_hw_tx_byte@plt>
cmp    $0x0,%eax
jne    1353 <main+0x1c3>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <i2c_hw_stop@plt>
mov    $0x0,%al
call   10b0 <i2c_deinit@plt>
movl   $0x4,-0x4(%rbp)
jmp    137b <main+0x1eb>
jmp    1358 <main+0x1c8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1292 <main+0x102>
mov    $0x0,%al
call   1050 <i2c_hw_stop@plt>
mov    $0x0,%al
call   10b0 <i2c_deinit@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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
call   1080 <i2c_getopt@plt>
cmp    $0x2,%ebx
jg     11ca <main+0x3a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%ebx
jmp    1308 <main+0x178>
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1208 <main+0x78>
cmpb   $0x0,(%rdx)
je     1208 <main+0x78>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1303 <main+0x173>
xor    %eax,%eax
call   1030 <i2c_init@plt>
xor    %eax,%eax
call   10a0 <i2c_hw_start@plt>
lea    (%r15,%r15,1),%edi
call   1090 <i2c_hw_tx_byte@plt>
test   %eax,%eax
je     127c <main+0xec>
mov    %ebx,%r12d
mov    $0x2,%ebx
lea    0x8(%rsp),%r15
mov    (%r14,%rbx,8),%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1253 <main+0xc3>
cmpb   $0x0,(%rdx)
jne    12de <main+0x14e>
mov    %ebp,%edi
call   1090 <i2c_hw_tx_byte@plt>
test   %eax,%eax
je     12ab <main+0x11b>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1230 <main+0xa0>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <i2c_hw_stop@plt>
xor    %eax,%eax
call   10b0 <i2c_deinit@plt>
jmp    1308 <main+0x178>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <i2c_hw_stop@plt>
xor    %eax,%eax
call   10b0 <i2c_deinit@plt>
mov    $0x3,%ebx
jmp    1308 <main+0x178>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
add    $0xffffffff,%ebx
lea    0xdd2(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <i2c_hw_stop@plt>
xor    %eax,%eax
call   10b0 <i2c_deinit@plt>
mov    $0x4,%ebx
jmp    1308 <main+0x178>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <i2c_hw_stop@plt>
xor    %eax,%eax
call   10b0 <i2c_deinit@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Usage: i2cset <address> <data ...>\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Conversion error at '%s'\0A\00"
@.str.2 = [42 x i8] c"Received NAK from slave 0x%02x, aborting\0A\00"
@.str.3 = [41 x i8] c"write command: conversion error at '%s'\0A\00"
@.str.4 = [37 x i8] c"Received NAK after byte %d (0x%02x)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @i2c_getopt(i32 %10, i8** %11)
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 1, i32* %3
br label %91
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, i8** %9, i32 0)
store i32 %22, i32* %7
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %34
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %9
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 2, i32* %3
br label %91
34: ; preds = %25, %18
%35 = call i32 (...) @i2c_init()
%36 = call i32 (...) @i2c_hw_start()
%37 = load i32, i32* %7
%38 = shl i32 %37, 1
%39 = call i32 @i2c_hw_tx_byte(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i32, i32* %7
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = call i32 (...) @i2c_hw_stop()
%46 = call i32 (...) @i2c_deinit()
store i32 3, i32* %3
br label %91
47: ; preds = %34
store i32 2, i32* %6
br label %48
48: ; preds = %85, %47
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %88
52: ; preds = %48
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strtol(i8* %57, i8** %9, i32 0)
store i32 %58, i32* %8
%59 = load i8*, i8** %9
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %72
61: ; preds = %52
%62 = load i8*, i8** %9
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %9
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %68)
%70 = call i32 (...) @i2c_hw_stop()
%71 = call i32 (...) @i2c_deinit()
store i32 2, i32* %3
br label %91
72: ; preds = %61, %52
%73 = load i32, i32* %8
%74 = call i32 @i2c_hw_tx_byte(i32 %73)
%75 = icmp ne i32 %74, 0
br i1 %75, label %84, label %76
76: ; preds = %72
%77 = load i32, i32* @stderr
%78 = load i32, i32* %6
%79 = sub nsw i32 %78, 1
%80 = load i32, i32* %8
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %79, i32 %80)
%82 = call i32 (...) @i2c_hw_stop()
%83 = call i32 (...) @i2c_deinit()
store i32 4, i32* %3
br label %91
84: ; preds = %72
br label %85
85: ; preds = %84
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %48
88: ; preds = %48
%89 = call i32 (...) @i2c_hw_stop()
%90 = call i32 (...) @i2c_deinit()
store i32 0, i32* %3
br label %91
91: ; preds = %88, %76, %66, %41, %30, %15
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str = [35 x i8] c"Usage: i2cset <address> <data ...>\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Conversion error at '%s'\0A\00"
@.str.2 = [42 x i8] c"Received NAK from slave 0x%02x, aborting\0A\00"
@.str.3 = [41 x i8] c"write command: conversion error at '%s'\0A\00"
@.str.4 = [37 x i8] c"Received NAK after byte %d (0x%02x)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @i2c_getopt(i32 %0, i8** %1)
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %66
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strtol(i8* %12, i8** %3, i32 0)
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %66
22: ; preds = %16, %10
%23 = tail call i32 (...) @i2c_init()
%24 = tail call i32 (...) @i2c_hw_start()
%25 = shl i32 %13, 1
%26 = tail call i32 @i2c_hw_tx_byte(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = zext i32 %0 to i64
br label %35
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%33 = tail call i32 (...) @i2c_hw_stop()
%34 = tail call i32 (...) @i2c_deinit()
br label %66
35: ; preds = %28, %60
%36 = phi i64 [ 2, %28 ], [ %61, %60 ]
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @strtol(i8* %38, i8** %3, i32 0)
%40 = load i8*, i8** %3
%41 = icmp eq i8* %40, null
br i1 %41, label %50, label %42
42: ; preds = %35
%43 = load i8, i8* %40
%44 = icmp eq i8 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%48 = tail call i32 (...) @i2c_hw_stop()
%49 = tail call i32 (...) @i2c_deinit()
br label %66
50: ; preds = %42, %35
%51 = tail call i32 @i2c_hw_tx_byte(i32 %39)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = trunc i64 %36 to i32
%55 = load i32, i32* @stderr
%56 = add nsw i32 %54, -1
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %39)
%58 = tail call i32 (...) @i2c_hw_stop()
%59 = tail call i32 (...) @i2c_deinit()
br label %66
60: ; preds = %50
%61 = add nuw nsw i64 %36, 1
%62 = icmp eq i64 %61, %29
br i1 %62, label %63, label %35
63: ; preds = %60
%64 = tail call i32 (...) @i2c_hw_stop()
%65 = tail call i32 (...) @i2c_deinit()
br label %66
66: ; preds = %63, %53, %45, %30, %19, %7
%67 = phi i32 [ 1, %7 ], [ 2, %19 ], [ 2, %45 ], [ 4, %53 ], [ 0, %63 ], [ 3, %30 ]
ret i32 %67
}