#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*/ TwAck();
unsigned char TwGet();
int TwPut(unsigned char);
int /*<<< orphan*/ TwStart();
int /*<<< orphan*/ TwStop();
int TwMasterTransact(unsigned char sla, void *txdata, unsigned short txlen,
                     void *rxdata, unsigned short rxsiz, unsigned long tmo) {
  int rc = 0;
  unsigned char *cp;
  if (txlen) {
    TwStart();
    if ((rc = TwPut(sla << 1)) == 0) {
      for (cp = (unsigned char *)txdata; txlen--; cp++) {
        if ((rc = TwPut(*cp)) != 0) {
          break;
        }
      }
    }
  }
  if (rc == 0 && rxsiz) {
    TwStart();
    if ((rc = TwPut((sla << 1) | 1)) == 0) {
      for (cp = rxdata;; cp++) {
        *cp = TwGet();
        if (++rc >= rxsiz) {
          break;
        }
        TwAck();
      }
    }
  }
  TwStop();
  return rc;
}


x86 assembly (clang, -O0):
<TwMasterTransact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8w,%ax
mov    %dil,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %dx,-0x12(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpw   $0x0,-0x12(%rbp)
je     1206 <TwMasterTransact+0xb6>
mov    $0x0,%al
call   1050 <TwStart@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
movzbl %al,%edi
call   1030 <TwPut@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1201 <TwMasterTransact+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x12(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x12(%rbp)
cmp    $0x0,%ax
je     11fc <TwMasterTransact+0xac>
mov    -0x40(%rbp),%rax
movzbl (%rax),%edi
call   1030 <TwPut@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     11e6 <TwMasterTransact+0x96>
jmp    11fc <TwMasterTransact+0xac>
jmp    11eb <TwMasterTransact+0x9b>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11b0 <TwMasterTransact+0x60>
jmp    1201 <TwMasterTransact+0xb1>
jmp    1206 <TwMasterTransact+0xb6>
cmpl   $0x0,-0x34(%rbp)
jne    1295 <TwMasterTransact+0x145>
movzwl -0x22(%rbp),%eax
cmp    $0x0,%eax
je     1295 <TwMasterTransact+0x145>
mov    $0x0,%al
call   1050 <TwStart@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
or     $0x1,%eax
movzbl %al,%edi
call   1030 <TwPut@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1290 <TwMasterTransact+0x140>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <TwGet@plt>
mov    %al,%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movzwl -0x22(%rbp),%ecx
cmp    %ecx,%eax
jl     1273 <TwMasterTransact+0x123>
jmp    128b <TwMasterTransact+0x13b>
mov    $0x0,%al
call   1070 <TwAck@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    124a <TwMasterTransact+0xfa>
jmp    1290 <TwMasterTransact+0x140>
jmp    1295 <TwMasterTransact+0x145>
mov    $0x0,%al
call   1060 <TwStop@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TwMasterTransact>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
mov    %rcx,%r15
mov    %edi,%r12d
test   %edx,%edx
je     11bc <TwMasterTransact+0x6c>
mov    %edx,%r13d
mov    %rsi,%r14
xor    %eax,%eax
call   1050 <TwStart@plt>
lea    (%r12,%r12,1),%eax
movzbl %al,%edi
call   1030 <TwPut@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1233 <TwMasterTransact+0xe3>
movzwl %r13w,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,1),%edi
call   1030 <TwPut@plt>
test   %eax,%eax
jne    1231 <TwMasterTransact+0xe1>
add    $0x1,%rbp
cmp    %bp,%r13w
jne    11a0 <TwMasterTransact+0x50>
cmpw   $0x0,0x4(%rsp)
je     122d <TwMasterTransact+0xdd>
xor    %eax,%eax
call   1050 <TwStart@plt>
add    %r12b,%r12b
or     $0x1,%r12b
movzbl %r12b,%edi
call   1030 <TwPut@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1233 <TwMasterTransact+0xe3>
xor    %eax,%eax
call   1040 <TwGet@plt>
mov    %al,(%r15)
mov    $0x1,%ebx
cmpw   $0x2,0x4(%rsp)
jb     1233 <TwMasterTransact+0xe3>
mov    0x4(%rsp),%eax
movzwl %ax,%ebx
movzwl %ax,%r14d
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <TwAck@plt>
xor    %eax,%eax
call   1040 <TwGet@plt>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    1210 <TwMasterTransact+0xc0>
jmp    1233 <TwMasterTransact+0xe3>
xor    %ebx,%ebx
jmp    1233 <TwMasterTransact+0xe3>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <TwStop@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @TwMasterTransact(i8 zeroext %0, i8* %1, i16 zeroext %2, i8* %3, i16 zeroext %4, i64 %5) {
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i8*
%11 = alloca i16
%12 = alloca i64
%13 = alloca i32
%14 = alloca i8*
store i8 %0, i8* %7
store i8* %1, i8** %8
store i16 %2, i16* %9
store i8* %3, i8** %10
store i16 %4, i16* %11
store i64 %5, i64* %12
store i32 0, i32* %13
%15 = load i16, i16* %9
%16 = icmp ne i16 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %6
%18 = call i32 (...) @TwStart()
%19 = load i8, i8* %7
%20 = zext i8 %19 to i32
%21 = shl i32 %20, 1
%22 = trunc i32 %21 to i8
%23 = call i32 @TwPut(i8 zeroext %22)
store i32 %23, i32* %13
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %17
%26 = load i8*, i8** %8
store i8* %26, i8** %14
br label %27
27: ; preds = %38, %25
%28 = load i16, i16* %9
%29 = add i16 %28, -1
store i16 %29, i16* %9
%30 = icmp ne i16 %28, 0
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i8*, i8** %14
%33 = load i8, i8* %32
%34 = call i32 @TwPut(i8 zeroext %33)
store i32 %34, i32* %13
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
br label %41
37: ; preds = %31
br label %38
38: ; preds = %37
%39 = load i8*, i8** %14
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %14
br label %27
41: ; preds = %36, %27
br label %42
42: ; preds = %41, %17
br label %43
43: ; preds = %42, %6
%44 = load i32, i32* %13
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %77
46: ; preds = %43
%47 = load i16, i16* %11
%48 = zext i16 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %77
50: ; preds = %46
%51 = call i32 (...) @TwStart()
%52 = load i8, i8* %7
%53 = zext i8 %52 to i32
%54 = shl i32 %53, 1
%55 = or i32 %54, 1
%56 = trunc i32 %55 to i8
%57 = call i32 @TwPut(i8 zeroext %56)
store i32 %57, i32* %13
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %50
%60 = load i8*, i8** %10
store i8* %60, i8** %14
br label %61
61: ; preds = %72, %59
%62 = call zeroext i8 (...) @TwGet()
%63 = load i8*, i8** %14
store i8 %62, i8* %63
%64 = load i32, i32* %13
%65 = add nsw i32 %64, 1
store i32 %65, i32* %13
%66 = load i16, i16* %11
%67 = zext i16 %66 to i32
%68 = icmp sge i32 %65, %67
br i1 %68, label %69, label %70
69: ; preds = %61
br label %75
70: ; preds = %61
%71 = call i32 (...) @TwAck()
br label %72
72: ; preds = %70
%73 = load i8*, i8** %14
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %14
br label %61
75: ; preds = %69
br label %76
76: ; preds = %75, %50
br label %77
77: ; preds = %76, %46, %43
%78 = call i32 (...) @TwStop()
%79 = load i32, i32* %13
ret i32 %79
}

LLVM IR (-O2):
define i32 @TwMasterTransact(i8 zeroext %0, i8* nocapture %1, i16 zeroext %2, i8* nocapture writeonly %3, i16 zeroext %4, i64 %5) {
%7 = icmp eq i16 %2, 0
br i1 %7, label %23, label %8
8: ; preds = %6
%9 = tail call i32 (...) @TwStart()
%10 = shl i8 %0, 1
%11 = tail call i32 @TwPut(i8 zeroext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %43
13: ; preds = %16
%14 = getelementptr inbounds i8, i8* %18, i64 1
%15 = icmp eq i16 %19, 0
br i1 %15, label %23, label %16
16: ; preds = %8, %13
%17 = phi i16 [ %19, %13 ], [ %2, %8 ]
%18 = phi i8* [ %14, %13 ], [ %1, %8 ]
%19 = add i16 %17, -1
%20 = load i8, i8* %18
%21 = tail call i32 @TwPut(i8 zeroext %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %13, label %43
23: ; preds = %13, %6
%24 = zext i16 %4 to i32
%25 = icmp eq i16 %4, 0
br i1 %25, label %43, label %26
26: ; preds = %23
%27 = tail call i32 (...) @TwStart()
%28 = shl i8 %0, 1
%29 = or i8 %28, 1
%30 = tail call i32 @TwPut(i8 zeroext %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %26
%33 = tail call zeroext i8 (...) @TwGet()
store i8 %33, i8* %3
%34 = icmp ugt i16 %4, 1
br i1 %34, label %35, label %43
35: ; preds = %32, %35
%36 = phi i32 [ %41, %35 ], [ 1, %32 ]
%37 = phi i8* [ %39, %35 ], [ %3, %32 ]
%38 = tail call i32 (...) @TwAck()
%39 = getelementptr inbounds i8, i8* %37, i64 1
%40 = tail call zeroext i8 (...) @TwGet()
store i8 %40, i8* %39
%41 = add nuw nsw i32 %36, 1
%42 = icmp eq i32 %41, %24
br i1 %42, label %43, label %35
43: ; preds = %16, %35, %32, %8, %26, %23
%44 = phi i32 [ %30, %26 ], [ 0, %23 ], [ %11, %8 ], [ 1, %32 ], [ %24, %35 ], [ %21, %16 ]
%45 = tail call i32 (...) @TwStop()
ret i32 %44
}