#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void parse_I2C(int SCL, int SDA) {
  static int in_data = 0, byte = 0, bit = 0;
  static int oldSCL = 1, oldSDA = 1;
  int xSCL, xSDA;
  if (SCL != oldSCL) {
    oldSCL = SCL;
    if (SCL)
      xSCL = 1;
    else
      xSCL = 0;
  } else
    xSCL = 2;
  if (SDA != oldSDA) {
    oldSDA = SDA;
    if (SDA)
      xSDA = 4;
    else
      xSDA = 0;
  } else
    xSDA = 8;
  switch (xSCL + xSDA) {
  case 1 + 4:
  case 1 + 0:
  case 1 + 8:
    if (in_data) {
      if (bit++ < 8) {
        byte <<= 1;
        byte |= SDA;
      } else {
        printf("%02X", byte);
        if (SDA)
          printf("-");
        else
          printf("+");
        bit = 0;
        byte = 0;
      }
    }
    break;
  case 0 + 4:
    break;
  case 0 + 0:
    break;
  case 0 + 8:
    break;
  case 2 + 4:
    if (SCL) {
      in_data = 0;
      byte = 0;
      bit = 0;
      printf("]\n");
      fflush(NULL);
    }
    break;
  case 2 + 0:
    if (SCL) {
      in_data = 1;
      byte = 0;
      bit = 0;
      printf("[");
    }
    break;
  case 2 + 8:
    break;
  }
}


x86 assembly (clang, -O0):
<parse_I2C>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    0x2ef9(%rip),%eax
je     1168 <parse_I2C+0x48>
mov    -0x4(%rbp),%eax
mov    %eax,0x2eea(%rip)
cmpl   $0x0,-0x4(%rbp)
je     115c <parse_I2C+0x3c>
movl   $0x1,-0xc(%rbp)
jmp    1163 <parse_I2C+0x43>
movl   $0x0,-0xc(%rbp)
jmp    116f <parse_I2C+0x4f>
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    0x2ebc(%rip),%eax
je     11a9 <parse_I2C+0x89>
mov    -0x8(%rbp),%eax
mov    %eax,0x2ead(%rip)
cmpl   $0x0,-0x8(%rbp)
je     119d <parse_I2C+0x7d>
movl   $0x4,-0x10(%rbp)
jmp    11a4 <parse_I2C+0x84>
movl   $0x0,-0x10(%rbp)
jmp    11b0 <parse_I2C+0x90>
movl   $0x8,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xa,%eax
ja     1315 <parse_I2C+0x1f5>
mov    -0x18(%rbp),%rax
lea    0xe2e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,0x2e5a(%rip)
je     127d <parse_I2C+0x15d>
mov    0x2e56(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e4b(%rip)
cmp    $0x8,%eax
jge    1225 <parse_I2C+0x105>
mov    0x2e38(%rip),%eax
shl    $0x1,%eax
mov    %eax,0x2e2f(%rip)
mov    -0x8(%rbp),%eax
or     0x2e26(%rip),%eax
mov    %eax,0x2e20(%rip)
jmp    1278 <parse_I2C+0x158>
mov    0x2e15(%rip),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1256 <parse_I2C+0x136>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1264 <parse_I2C+0x144>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,0x2dd6(%rip)
movl   $0x0,0x2dc8(%rip)
jmp    127d <parse_I2C+0x15d>
jmp    1315 <parse_I2C+0x1f5>
jmp    1315 <parse_I2C+0x1f5>
jmp    1315 <parse_I2C+0x1f5>
jmp    1315 <parse_I2C+0x1f5>
cmpl   $0x0,-0x4(%rbp)
je     12d0 <parse_I2C+0x1b0>
movl   $0x0,0x2d97(%rip)
movl   $0x0,0x2d91(%rip)
movl   $0x0,0x2d8b(%rip)
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
jmp    1315 <parse_I2C+0x1f5>
cmpl   $0x0,-0x4(%rbp)
je     130b <parse_I2C+0x1eb>
movl   $0x1,0x2d53(%rip)
movl   $0x0,0x2d4d(%rip)
movl   $0x0,0x2d47(%rip)
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1315 <parse_I2C+0x1f5>
jmp    1315 <parse_I2C+0x1f5>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_I2C>:
push   %rbx
mov    %esi,%ebx
mov    $0x2,%eax
cmp    %edi,0x2ef2(%rip)
je     115d <parse_I2C+0x1d>
mov    %edi,0x2eea(%rip)
xor    %eax,%eax
test   %edi,%edi
setne  %al
mov    $0x8,%ecx
cmp    %ebx,0x2edc(%rip)
je     117a <parse_I2C+0x3a>
mov    %ebx,0x2ed4(%rip)
xor    %ecx,%ecx
test   %ebx,%ebx
setne  %cl
shl    $0x2,%ecx
or     %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0x8,%ecx
ja     1260 <parse_I2C+0x120>
lea    0xe71(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
cmpb   $0x1,0x2ead(%rip)
jne    1260 <parse_I2C+0x120>
mov    0x2ea9(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ea0(%rip)
mov    0x2e96(%rip),%esi
cmp    $0x7,%eax
jg     122c <parse_I2C+0xec>
add    %esi,%esi
or     %ebx,%esi
mov    %esi,0x2e87(%rip)
pop    %rbx
ret
test   %edi,%edi
je     1260 <parse_I2C+0x120>
movb   $0x1,0x2e72(%rip)
movl   $0x0,0x2e6c(%rip)
movl   $0x0,0x2e66(%rip)
mov    $0x5b,%edi
pop    %rbx
jmp    1030 <putchar@plt>
test   %edi,%edi
je     1260 <parse_I2C+0x120>
movb   $0x0,0x2e48(%rip)
movl   $0x0,0x2e42(%rip)
movl   $0x0,0x2e3c(%rip)
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
pop    %rbx
jmp    1060 <fflush@plt>
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
lea    (%rax,%rax,1),%edi
add    $0x2b,%edi
call   1030 <putchar@plt>
movl   $0x0,0x2dfe(%rip)
movl   $0x0,0x2df0(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@parse_I2C.in_data = internal global i32 0
@parse_I2C.byte = internal global i32 0
@parse_I2C.bit = internal global i32 0
@parse_I2C.oldSCL = internal global i32 1
@parse_I2C.oldSDA = internal global i32 1
@.str = [5 x i8] c"%02X\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [3 x i8] c"]\0A\00"
@.str.4 = [2 x i8] c"[\00"
define void @parse_I2C(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @parse_I2C.oldSCL
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* %3
store i32 %11, i32* @parse_I2C.oldSCL
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %5
br label %16
15: ; preds = %10
store i32 0, i32* %5
br label %16
16: ; preds = %15, %14
br label %18
17: ; preds = %2
store i32 2, i32* %5
br label %18
18: ; preds = %17, %16
%19 = load i32, i32* %4
%20 = load i32, i32* @parse_I2C.oldSDA
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i32, i32* %4
store i32 %23, i32* @parse_I2C.oldSDA
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 4, i32* %6
br label %28
27: ; preds = %22
store i32 0, i32* %6
br label %28
28: ; preds = %27, %26
br label %30
29: ; preds = %18
store i32 8, i32* %6
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = add nsw i32 %31, %32
switch i32 %33, label %76 [
i32 5, label %34
i32 1, label %34
i32 9, label %34
i32 4, label %59
i32 0, label %60
i32 8, label %61
i32 6, label %62
i32 2, label %69
i32 10, label %75
]
34: ; preds = %30, %30, %30
%35 = load i32, i32* @parse_I2C.in_data
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %34
%38 = load i32, i32* @parse_I2C.bit
%39 = add nsw i32 %38, 1
store i32 %39, i32* @parse_I2C.bit
%40 = icmp slt i32 %38, 8
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32, i32* @parse_I2C.byte
%43 = shl i32 %42, 1
store i32 %43, i32* @parse_I2C.byte
%44 = load i32, i32* %4
%45 = load i32, i32* @parse_I2C.byte
%46 = or i32 %45, %44
store i32 %46, i32* @parse_I2C.byte
br label %57
47: ; preds = %37
%48 = load i32, i32* @parse_I2C.byte
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %56
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
store i32 0, i32* @parse_I2C.bit
store i32 0, i32* @parse_I2C.byte
br label %57
57: ; preds = %56, %41
br label %58
58: ; preds = %57, %34
br label %76
59: ; preds = %30
br label %76
60: ; preds = %30
br label %76
61: ; preds = %30
br label %76
62: ; preds = %30
%63 = load i32, i32* %3
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %62
store i32 0, i32* @parse_I2C.in_data
store i32 0, i32* @parse_I2C.byte
store i32 0, i32* @parse_I2C.bit
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%67 = call i32 @fflush(i32* null)
br label %68
68: ; preds = %65, %62
br label %76
69: ; preds = %30
%70 = load i32, i32* %3
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
store i32 1, i32* @parse_I2C.in_data
store i32 0, i32* @parse_I2C.byte
store i32 0, i32* @parse_I2C.bit
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
br label %76
75: ; preds = %30
br label %76
76: ; preds = %30, %75, %74, %68, %61, %60, %59, %58
ret void
}

LLVM IR (-O2):
@parse_I2C.in_data = internal unnamed_addr global i1 false
@parse_I2C.byte = internal unnamed_addr global i32 0
@parse_I2C.bit = internal unnamed_addr global i32 0
@parse_I2C.oldSCL = internal unnamed_addr global i32 1
@parse_I2C.oldSDA = internal unnamed_addr global i32 1
@.str = [5 x i8] c"%02X\00"
@str = [2 x i8] c"]\00"
define void @parse_I2C(i32 %0, i32 %1) {
%3 = load i32, i32* @parse_I2C.oldSCL
%4 = icmp eq i32 %3, %0
br i1 %4, label %8, label %5
5: ; preds = %2
store i32 %0, i32* @parse_I2C.oldSCL
%6 = icmp ne i32 %0, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %7, %5 ], [ 2, %2 ]
%10 = load i32, i32* @parse_I2C.oldSDA
%11 = icmp eq i32 %10, %1
br i1 %11, label %15, label %12
12: ; preds = %8
store i32 %1, i32* @parse_I2C.oldSDA
%13 = icmp eq i32 %1, 0
%14 = select i1 %13, i32 0, i32 4
br label %15
15: ; preds = %8, %12
%16 = phi i32 [ %14, %12 ], [ 8, %8 ]
%17 = or i32 %16, %9
switch i32 %17, label %42 [
i32 5, label %18
i32 1, label %18
i32 9, label %18
i32 2, label %38
i32 6, label %33
]
18: ; preds = %15, %15, %15
%19 = load i1, i1* @parse_I2C.in_data
br i1 %19, label %20, label %42
20: ; preds = %18
%21 = load i32, i32* @parse_I2C.bit
%22 = add nsw i32 %21, 1
store i32 %22, i32* @parse_I2C.bit
%23 = icmp slt i32 %21, 8
%24 = load i32, i32* @parse_I2C.byte
br i1 %23, label %25, label %28
25: ; preds = %20
%26 = shl i32 %24, 1
%27 = or i32 %26, %1
store i32 %27, i32* @parse_I2C.byte
br label %42
28: ; preds = %20
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%30 = icmp eq i32 %1, 0
%31 = select i1 %30, i32 43, i32 45
%32 = tail call i32 @putchar(i32 %31)
store i32 0, i32* @parse_I2C.bit
store i32 0, i32* @parse_I2C.byte
br label %42
33: ; preds = %15
%34 = icmp eq i32 %0, 0
br i1 %34, label %42, label %35
35: ; preds = %33
store i1 false, i1* @parse_I2C.in_data
store i32 0, i32* @parse_I2C.byte
store i32 0, i32* @parse_I2C.bit
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%37 = tail call i32 @fflush(i32* null)
br label %42
38: ; preds = %15
%39 = icmp eq i32 %0, 0
br i1 %39, label %42, label %40
40: ; preds = %38
store i1 true, i1* @parse_I2C.in_data
store i32 0, i32* @parse_I2C.byte
store i32 0, i32* @parse_I2C.bit
%41 = tail call i32 @putchar(i32 91)
br label %42
42: ; preds = %38, %40, %33, %35, %18, %28, %25, %15
ret void
}