#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*/ _IO(char, int);
int errno;
int ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ printf(char *, int, uintptr_t, unsigned long long);
int do_getplist(int fd) {
  uintptr_t plist[(4096 / sizeof(void *))];
  int i, size;
  size = ioctl(fd, _IO('4', 6));
  if (size < 0)
    return -errno;
  i = ioctl(fd, _IO('4', 8), plist);
  if (i < 0)
    return -errno;
  for (i = 0; i < size / 4096; i++)
    printf("buf 0x%08x: pfn 0x%08x, addr 0x%012llx\n", i * 4096, plist[i],
           (unsigned long long)plist[i] << 12);
  return 0;
}


x86 assembly (clang, -O0):
<do_getplist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x101c(%rbp)
mov    $0x34,%edi
mov    $0x6,%esi
call   1040 <_IO@plt>
mov    -0x101c(%rbp),%edi
mov    %eax,%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,-0x1018(%rbp)
cmpl   $0x0,-0x1018(%rbp)
jge    118b <do_getplist+0x5b>
xor    %eax,%eax
mov    0x2e5f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <do_getplist+0x135>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1020(%rbp)
mov    $0x34,%edi
mov    $0x8,%esi
call   1040 <_IO@plt>
mov    -0x1020(%rbp),%edi
mov    %eax,%esi
lea    -0x1010(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jge    11df <do_getplist+0xaf>
xor    %eax,%eax
mov    0x2e0b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <do_getplist+0x135>
movl   $0x0,-0x1014(%rbp)
mov    -0x1014(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x1018(%rbp),%eax
mov    $0x1000,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1024(%rbp),%eax
cmp    %ecx,%eax
jge    125e <do_getplist+0x12e>
mov    -0x1014(%rbp),%esi
shl    $0xc,%esi
movslq -0x1014(%rbp),%rax
mov    -0x1010(%rbp,%rax,8),%rdx
ff
movslq -0x1014(%rbp),%rax
mov    -0x1010(%rbp,%rax,8),%rcx
ff
shl    $0xc,%rcx
lea    0xdbb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    11e9 <do_getplist+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_getplist>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %edi,%ebp
mov    $0x34,%edi
mov    $0x6,%esi
call   1040 <_IO@plt>
xor    %r14d,%r14d
mov    %ebp,%edi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <ioctl@plt>
test   %eax,%eax
js     11d6 <do_getplist+0xa6>
mov    %eax,%r15d
mov    $0x34,%edi
mov    $0x8,%esi
call   1040 <_IO@plt>
xor    %r14d,%r14d
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
test   %eax,%eax
js     11df <do_getplist+0xaf>
cmp    $0x1000,%r15d
jb     11ec <do_getplist+0xbc>
and    $0xfffff000,%r15d
xor    %r14d,%r14d
lea    0xe5a(%rip),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdx
mov    %rdx,%rcx
shl    $0xc,%rcx
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1000,%rbp
add    $0x8,%rbx
cmp    %rbp,%r15
jne    11b0 <do_getplist+0x80>
jmp    11ec <do_getplist+0xbc>
mov    0x2e03(%rip),%rax
jmp    11e9 <do_getplist+0xb9>
mov    0x2dfa(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    %r14d,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [40 x i8] c"buf 0x%08x: pfn 0x%08x, addr 0x%012llx\0A\00"
define i32 @do_getplist(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i64]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @_IO(i8 signext 52, i32 6)
%9 = call i32 (i32, i32, ...) @ioctl(i32 %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
store i32 %14, i32* %2
br label %48
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @_IO(i8 signext 52, i32 8)
%18 = getelementptr inbounds [512 x i64], [512 x i64]* %4, i64 0, i64 0
%19 = call i32 (i32, i32, ...) @ioctl(i32 %16, i32 %17, i64* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = sub nsw i32 0, %23
store i32 %24, i32* %2
br label %48
25: ; preds = %15
store i32 0, i32* %5
br label %26
26: ; preds = %44, %25
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = sdiv i32 %28, 4096
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %47
31: ; preds = %26
%32 = load i32, i32* %5
%33 = mul nsw i32 %32, 4096
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [512 x i64], [512 x i64]* %4, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [512 x i64], [512 x i64]* %4, i64 0, i64 %39
%41 = load i64, i64* %40
%42 = shl i64 %41, 12
%43 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %33, i64 %37, i64 %42)
br label %44
44: ; preds = %31
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %26
47: ; preds = %26
store i32 0, i32* %2
br label %48
48: ; preds = %47, %22, %12
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [40 x i8] c"buf 0x%08x: pfn 0x%08x, addr 0x%012llx\0A\00"
define i32 @do_getplist(i32 %0) {
%2 = alloca [512 x i64]
%3 = bitcast [512 x i64]* %2 to i8*
%4 = tail call i32 @_IO(i8 signext 52, i32 6)
%5 = tail call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %33
10: ; preds = %1
%11 = tail call i32 @_IO(i8 signext 52, i32 8)
%12 = getelementptr inbounds [512 x i64], [512 x i64]* %2, i64 0, i64 0
%13 = call i32 (i32, i32, ...) @ioctl(i32 %0, i32 %11, i64* %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = icmp ugt i32 %5, 4095
br i1 %16, label %17, label %33
17: ; preds = %15
%18 = lshr i32 %5, 12
%19 = zext i32 %18 to i64
br label %23
20: ; preds = %10
%21 = load i32, i32* @errno
%22 = sub nsw i32 0, %21
br label %33
23: ; preds = %17, %23
%24 = phi i64 [ 0, %17 ], [ %31, %23 ]
%25 = getelementptr inbounds [512 x i64], [512 x i64]* %2, i64 0, i64 %24
%26 = load i64, i64* %25
%27 = shl i64 %26, 12
%28 = trunc i64 %24 to i32
%29 = shl i32 %28, 12
%30 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %29, i64 %26, i64 %27)
%31 = add nuw nsw i64 %24, 1
%32 = icmp eq i64 %31, %19
br i1 %32, label %33, label %23
33: ; preds = %23, %15, %20, %7
%34 = phi i32 [ %9, %7 ], [ %22, %20 ], [ 0, %15 ], [ 0, %23 ]
ret i32 %34
}