#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 smc_in(int);
int /*<<< orphan*/ smc_out(int, unsigned int);
void read_data(unsigned char page, unsigned char offset, unsigned char count,
               unsigned char shortlong, unsigned char *user_buffer) {
  unsigned int address;
  address = (page << 9) + offset;
  smc_out(2, (address >> 8) | 0xc0);
  smc_out(3, address);
  while (count != 0) {
    *user_buffer = smc_in(4);
    user_buffer++;
    count--;
  }
  if (shortlong == 1) {
    count = 0;
    do {
      *user_buffer = smc_in(4);
      user_buffer++;
      count--;
    } while (count != 0);
  }
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %cl,-0x3(%rbp)
mov    %al,-0x4(%rbp)
mov    %r8,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
shl    $0x9,%eax
movzbl -0x2(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
shr    $0x8,%esi
or     $0xc0,%esi
mov    $0x2,%edi
call   1030 <smc_out@plt>
mov    -0x14(%rbp),%esi
mov    $0x3,%edi
call   1030 <smc_out@plt>
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
je     11ae <read_data+0x8e>
mov    $0x4,%edi
call   1040 <smc_in@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x3(%rbp),%al
add    $0xff,%al
mov    %al,-0x3(%rbp)
jmp    1176 <read_data+0x56>
movzbl -0x4(%rbp),%eax
cmp    $0x1,%eax
jne    11f7 <read_data+0xd7>
movb   $0x0,-0x3(%rbp)
mov    $0x4,%edi
call   1040 <smc_in@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x3(%rbp),%al
add    $0xff,%al
mov    %al,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jne    11bf <read_data+0x9f>
jmp    11f7 <read_data+0xd7>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%eax
shl    $0x9,%eax
or     %eax,%r15d
or     $0x60,%edi
lea    (%rdi,%rdi,1),%esi
mov    $0x2,%edi
call   1030 <smc_out@plt>
mov    $0x3,%edi
mov    %r15d,%esi
call   1030 <smc_out@plt>
test   %ebp,%ebp
je     1176 <read_data+0x56>
nopl   0x0(%rax,%rax,1)
mov    $0x4,%edi
call   1040 <smc_in@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xff,%bpl
jne    1160 <read_data+0x40>
cmp    $0x1,%r14b
jne    1196 <read_data+0x76>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    $0x4,%edi
call   1040 <smc_in@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
test   %bpl,%bpl
jne    1180 <read_data+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_data(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8* %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
store i8* %4, i8** %10
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = shl i32 %13, 9
%15 = load i8, i8* %7
%16 = zext i8 %15 to i32
%17 = add nsw i32 %14, %16
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = lshr i32 %18, 8
%20 = or i32 %19, 192
%21 = call i32 @smc_out(i32 2, i32 %20)
%22 = load i32, i32* %11
%23 = call i32 @smc_out(i32 3, i32 %22)
br label %24
24: ; preds = %28, %5
%25 = load i8, i8* %8
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = call zeroext i8 @smc_in(i32 4)
%30 = load i8*, i8** %10
store i8 %29, i8* %30
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %10
%33 = load i8, i8* %8
%34 = add i8 %33, -1
store i8 %34, i8* %8
br label %24
35: ; preds = %24
%36 = load i8, i8* %9
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %52
39: ; preds = %35
store i8 0, i8* %8
br label %40
40: ; preds = %47, %39
%41 = call zeroext i8 @smc_in(i32 4)
%42 = load i8*, i8** %10
store i8 %41, i8* %42
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %10
%45 = load i8, i8* %8
%46 = add i8 %45, -1
store i8 %46, i8* %8
br label %47
47: ; preds = %40
%48 = load i8, i8* %8
%49 = zext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %40, label %51
51: ; preds = %47
br label %52
52: ; preds = %51, %35
ret void
}

LLVM IR (-O2):
define void @read_data(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8* nocapture writeonly %4) {
%6 = zext i8 %0 to i32
%7 = shl nuw nsw i32 %6, 9
%8 = zext i8 %1 to i32
%9 = or i32 %7, %8
%10 = shl nuw nsw i32 %6, 1
%11 = or i32 %10, 192
%12 = tail call i32 @smc_out(i32 2, i32 %11)
%13 = tail call i32 @smc_out(i32 3, i32 %9)
%14 = icmp eq i8 %2, 0
br i1 %14, label %22, label %15
15: ; preds = %5, %15
%16 = phi i8 [ %20, %15 ], [ %2, %5 ]
%17 = phi i8* [ %19, %15 ], [ %4, %5 ]
%18 = tail call zeroext i8 @smc_in(i32 4)
store i8 %18, i8* %17
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = add i8 %16, -1
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %15
22: ; preds = %15, %5
%23 = phi i8* [ %4, %5 ], [ %19, %15 ]
%24 = icmp eq i8 %3, 1
br i1 %24, label %25, label %32
25: ; preds = %22, %25
%26 = phi i8* [ %29, %25 ], [ %23, %22 ]
%27 = phi i8 [ %30, %25 ], [ 0, %22 ]
%28 = tail call zeroext i8 @smc_in(i32 4)
store i8 %28, i8* %26
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = add i8 %27, -1
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %25
32: ; preds = %25, %22
ret void
}