#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 */
typedef scalar_t__ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int kvss905c_read(int, int, scalar_t__, int, scalar_t__ *, int, scalar_t__ *);
int /*<<< orphan*/ memset(scalar_t__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/ const);
int kvss905c_picture_size(int fd, uint8_t page, uint8_t back, uint32_t *width,
                          uint32_t *height, uint8_t *requestsense) {
  uint8_t buffer[16];
  memset(buffer, 0, sizeof(buffer));
  const int r = kvss905c_read(fd, 0x80, page, back ? 0x80 : 0, buffer,
                              sizeof(buffer), requestsense);
  if (r)
    return r;
  const uint32_t width_be = *((uint32_t *)buffer);
  const uint32_t height_be = *((uint32_t *)&buffer[4]);
  if (width)
    *width = ntohl(width_be);
  if (height)
    *height = ntohl(height_be);
  return 0;
}


x86 assembly (clang, -O0):
<kvss905c_picture_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rsi
xor    %ecx,%ecx
mov    $0x80,%eax
cmp    $0x0,%rsi
cmovne %eax,%ecx
lea    -0xb0(%rbp),%r8
mov    -0x30(%rbp),%rax
mov    $0x80,%r9d
mov    %r9d,%esi
mov    %rax,(%rsp)
call   1040 <kvss905c_read@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
je     11bc <kvss905c_picture_size+0x8c>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <kvss905c_picture_size+0xe7>
mov    -0xb0(%rbp),%eax
mov    %eax,-0xb8(%rbp)
mov    -0x90(%rbp),%eax
mov    %eax,-0xbc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f2 <kvss905c_picture_size+0xc2>
mov    -0xb8(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1210 <kvss905c_picture_size+0xe0>
mov    -0xbc(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvss905c_picture_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,%r15
mov    %r8,0x8(%rsp)
mov    %rcx,%r12
mov    %rsi,%r13
mov    %edi,%ebp
xor    %ebx,%ebx
test   %rdx,%rdx
setne  %bl
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
shl    $0x7,%ebx
mov    %r15,(%rsp)
mov    %ebp,%edi
mov    $0x80,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %r14,%r8
mov    $0x80,%r9d
call   1040 <kvss905c_read@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11bf <kvss905c_picture_size+0x8f>
mov    0x8(%rsp),%rbx
mov    0x30(%rsp),%r15d
test   %r12,%r12
je     11b0 <kvss905c_picture_size+0x80>
mov    0x10(%rsp),%edi
call   1050 <ntohl@plt>
mov    %eax,(%r12)
test   %rbx,%rbx
je     11bf <kvss905c_picture_size+0x8f>
mov    %r15d,%edi
call   1050 <ntohl@plt>
mov    %eax,(%rbx)
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kvss905c_picture_size(i32 %0, i64 %1, i64 %2, i32* %3, i32* %4, i64* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64*
%14 = alloca [16 x i64]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %8
store i64 %1, i64* %9
store i64 %2, i64* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i64* %5, i64** %13
%18 = getelementptr inbounds [16 x i64], [16 x i64]* %14, i64 0, i64 0
%19 = call i32 @memset(i64* %18, i32 0, i32 128)
%20 = load i32, i32* %8
%21 = load i64, i64* %9
%22 = load i64, i64* %10
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 128, i32 0
%26 = getelementptr inbounds [16 x i64], [16 x i64]* %14, i64 0, i64 0
%27 = load i64*, i64** %13
%28 = call i32 @kvss905c_read(i32 %20, i32 128, i64 %21, i32 %25, i64* %26, i32 128, i64* %27)
store i32 %28, i32* %15
%29 = load i32, i32* %15
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %6
%32 = load i32, i32* %15
store i32 %32, i32* %7
br label %54
33: ; preds = %6
%34 = getelementptr inbounds [16 x i64], [16 x i64]* %14, i64 0, i64 0
%35 = bitcast i64* %34 to i32*
%36 = load i32, i32* %35
store i32 %36, i32* %16
%37 = getelementptr inbounds [16 x i64], [16 x i64]* %14, i64 0, i64 4
%38 = bitcast i64* %37 to i32*
%39 = load i32, i32* %38
store i32 %39, i32* %17
%40 = load i32*, i32** %11
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %33
%43 = load i32, i32* %16
%44 = call i32 @ntohl(i32 %43)
%45 = load i32*, i32** %11
store i32 %44, i32* %45
br label %46
46: ; preds = %42, %33
%47 = load i32*, i32** %12
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %17
%51 = call i32 @ntohl(i32 %50)
%52 = load i32*, i32** %12
store i32 %51, i32* %52
br label %53
53: ; preds = %49, %46
store i32 0, i32* %7
br label %54
54: ; preds = %53, %31
%55 = load i32, i32* %7
ret i32 %55
}

LLVM IR (-O2):
define i32 @kvss905c_picture_size(i32 %0, i64 %1, i64 %2, i32* writeonly %3, i32* writeonly %4, i64* %5) {
%7 = alloca [16 x i64]
%8 = bitcast [16 x i64]* %7 to i8*
%9 = getelementptr inbounds [16 x i64], [16 x i64]* %7, i64 0, i64 0
%10 = call i32 @memset(i64* %9, i32 0, i32 128)
%11 = icmp eq i64 %2, 0
%12 = select i1 %11, i32 0, i32 128
%13 = call i32 @kvss905c_read(i32 %0, i32 128, i64 %1, i32 %12, i64* %9, i32 128, i64* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %6
%16 = getelementptr inbounds [16 x i64], [16 x i64]* %7, i64 0, i64 4
%17 = bitcast i64* %16 to i32*
%18 = load i32, i32* %17
%19 = icmp eq i32* %3, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = bitcast [16 x i64]* %7 to i32*
%22 = load i32, i32* %21
%23 = call i32 @ntohl(i32 %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %15
%25 = icmp eq i32* %4, null
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = call i32 @ntohl(i32 %18)
store i32 %27, i32* %4
br label %28
28: ; preds = %24, %26, %6
ret i32 %13
}