#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 */
unsigned char clockin(int, unsigned int);
unsigned int ReadWriteData(unsigned int in_data) {
  int i;
  unsigned int out_data = 0;
  unsigned char out_bit;
  clockin(1, 0);
  clockin(0, 0);
  clockin(0, 0);
  for (i = 0; i < 32; i++) {
    out_bit = clockin((i == 31), ((in_data >> i) & 1));
    out_data = out_data | (out_bit << i);
  }
  clockin(1, 0);
  clockin(0, 0);
  return out_data;
}


x86 assembly (clang, -O0):
<ReadWriteData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <clockin@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <clockin@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    1191 <ReadWriteData+0x81>
cmpl   $0x1f,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%ecx
shr    %cl,%esi
and    $0x1,%esi
call   1030 <clockin@plt>
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
movzbl -0xd(%rbp),%edx
mov    -0x8(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1147 <ReadWriteData+0x37>
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <clockin@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadWriteData>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %edi,%edi
cmp    $0x1f,%ebp
sete   %dil
mov    %r14d,%esi
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
call   1030 <clockin@plt>
movzbl %al,%eax
mov    %ebp,%ecx
shl    %cl,%eax
or     %eax,%ebx
add    $0x1,%ebp
cmp    $0x20,%ebp
jne    1140 <ReadWriteData+0x30>
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <clockin@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ReadWriteData(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %4
%6 = call zeroext i8 @clockin(i32 1, i32 0)
%7 = call zeroext i8 @clockin(i32 0, i32 0)
%8 = call zeroext i8 @clockin(i32 0, i32 0)
store i32 0, i32* %3
br label %9
9: ; preds = %27, %1
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 31
%15 = zext i1 %14 to i32
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = lshr i32 %16, %17
%19 = and i32 %18, 1
%20 = call zeroext i8 @clockin(i32 %15, i32 %19)
store i8 %20, i8* %5
%21 = load i32, i32* %4
%22 = load i8, i8* %5
%23 = zext i8 %22 to i32
%24 = load i32, i32* %3
%25 = shl i32 %23, %24
%26 = or i32 %21, %25
store i32 %26, i32* %4
br label %27
27: ; preds = %12
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %9
30: ; preds = %9
%31 = call zeroext i8 @clockin(i32 1, i32 0)
%32 = call zeroext i8 @clockin(i32 0, i32 0)
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @ReadWriteData(i32 %0) {
%2 = tail call zeroext i8 @clockin(i32 1, i32 0)
%3 = tail call zeroext i8 @clockin(i32 0, i32 0)
%4 = tail call zeroext i8 @clockin(i32 0, i32 0)
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ 0, %1 ], [ %16, %5 ]
%7 = phi i32 [ 0, %1 ], [ %15, %5 ]
%8 = icmp eq i32 %6, 31
%9 = zext i1 %8 to i32
%10 = lshr i32 %0, %6
%11 = and i32 %10, 1
%12 = tail call zeroext i8 @clockin(i32 %9, i32 %11)
%13 = zext i8 %12 to i32
%14 = shl i32 %13, %6
%15 = or i32 %14, %7
%16 = add nuw nsw i32 %6, 1
%17 = icmp eq i32 %16, 32
br i1 %17, label %18, label %5
18: ; preds = %5
%19 = tail call zeroext i8 @clockin(i32 1, i32 0)
%20 = tail call zeroext i8 @clockin(i32 0, i32 0)
ret i32 %15
}