#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 */
char sl8Read(int);
int /*<<< orphan*/ sl8Write(int, char);
int sl8RegTest(void) {
  int i, iRet = 0;
  char cData;
  char cBuf[256];
  for (i = 16; i < 256; i++) {
    cBuf[i] = sl8Read(i);
    sl8Write(i, i);
  }
  for (i = 16; i < 256; i++) {
    cData = sl8Read(i);
    if (cData != i) {
      iRet = -1;
    }
  }
  for (i = 16; i < 256; i++) {
    sl8Write(i, cBuf[i]);
  }
  return iRet;
}


x86 assembly (clang, -O0):
<sl8RegTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x10,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    1177 <sl8RegTest+0x57>
mov    -0x4(%rbp),%edi
call   1030 <sl8Read@plt>
mov    %al,%cl
movslq -0x4(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%eax
movsbl %al,%esi
call   1040 <sl8Write@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1139 <sl8RegTest+0x19>
movl   $0x10,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    11bd <sl8RegTest+0x9d>
mov    -0x4(%rbp),%edi
call   1030 <sl8Read@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11aa <sl8RegTest+0x8a>
movl   $0xffffffff,-0x8(%rbp)
jmp    11af <sl8RegTest+0x8f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117e <sl8RegTest+0x5e>
movl   $0x10,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    11f3 <sl8RegTest+0xd3>
mov    -0x4(%rbp),%edi
movslq -0x4(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%esi
ff
call   1040 <sl8Write@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <sl8RegTest+0xa4>
mov    -0x8(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sl8RegTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    $0x10,%ebx
mov    %ebx,%edi
call   1030 <sl8Read@plt>
mov    %al,(%rsp,%rbx,1)
movsbl %bl,%esi
mov    %ebx,%edi
call   1040 <sl8Write@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1130 <sl8RegTest+0x10>
xor    %ebx,%ebx
mov    $0x10,%ebp
mov    $0xffffffff,%r14d
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <sl8Read@plt>
movsbl %al,%eax
cmp    %eax,%ebp
cmovne %r14d,%ebx
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1160 <sl8RegTest+0x40>
mov    $0x10,%ebp
movsbl (%rsp,%rbp,1),%esi
mov    %ebp,%edi
call   1040 <sl8Write@plt>
add    $0x1,%rbp
cmp    $0x100,%rbp
jne    1180 <sl8RegTest+0x60>
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sl8RegTest() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca [256 x i8]
store i32 0, i32* %2
store i32 16, i32* %1
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 256
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %1
%10 = call signext i8 @sl8Read(i32 %9)
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %12
store i8 %10, i8* %13
%14 = load i32, i32* %1
%15 = load i32, i32* %1
%16 = trunc i32 %15 to i8
%17 = call i32 @sl8Write(i32 %14, i8 signext %16)
br label %18
18: ; preds = %8
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %5
21: ; preds = %5
store i32 16, i32* %1
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %1
%24 = icmp slt i32 %23, 256
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32, i32* %1
%27 = call signext i8 @sl8Read(i32 %26)
store i8 %27, i8* %3
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = load i32, i32* %1
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 -1, i32* %2
br label %33
33: ; preds = %32, %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %22
37: ; preds = %22
store i32 16, i32* %1
br label %38
38: ; preds = %48, %37
%39 = load i32, i32* %1
%40 = icmp slt i32 %39, 256
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i32, i32* %1
%43 = load i32, i32* %1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @sl8Write(i32 %42, i8 signext %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %1
%50 = add nsw i32 %49, 1
store i32 %50, i32* %1
br label %38
51: ; preds = %38
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @sl8RegTest() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 16, %0 ], [ %10, %3 ]
%5 = trunc i64 %4 to i32
%6 = tail call signext i8 @sl8Read(i32 %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %4
store i8 %6, i8* %7
%8 = trunc i64 %4 to i8
%9 = tail call i32 @sl8Write(i32 %5, i8 signext %8)
%10 = add nuw nsw i64 %4, 1
%11 = icmp eq i64 %10, 256
br i1 %11, label %12, label %3
12: ; preds = %3, %12
%13 = phi i32 [ %19, %12 ], [ 16, %3 ]
%14 = phi i32 [ %18, %12 ], [ 0, %3 ]
%15 = tail call signext i8 @sl8Read(i32 %13)
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %13, %16
%18 = select i1 %17, i32 %14, i32 -1
%19 = add nuw nsw i32 %13, 1
%20 = icmp eq i32 %19, 256
br i1 %20, label %21, label %12
21: ; preds = %12, %21
%22 = phi i64 [ %27, %21 ], [ 16, %12 ]
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = trunc i64 %22 to i32
%26 = tail call i32 @sl8Write(i32 %25, i8 signext %24)
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, 256
br i1 %28, label %29, label %21
29: ; preds = %21
ret i32 %18
}