#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*/ memcpy(unsigned char *, void *, int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
unsigned int read_segofs16(unsigned char *);
void print_vbe_info(unsigned char *vbe_buf) {
  unsigned mode = 0;
  unsigned char buf2[0x100];
  unsigned u, ml;
  unsigned modelist[0x100];
  unsigned modes, number;
  int err;
  double d;
  char s[64];
  unsigned version, oem_version, memory, attributes, width, height,
      bytes_p_line;
  unsigned win_A_start, win_B_start, win_A_attr, win_B_attr, win_gran, win_size;
  unsigned bpp, res_bpp, fb_start, pixel_clock;
  version = vbe_buf[0x04];
  oem_version = vbe_buf[0x14];
  memory = vbe_buf[0x12] << 16;
  if (!mode) {
    printf("version = %u.%u, oem version = %u.%u\n", version >> 8,
           version & 0xff, oem_version >> 8, oem_version & 0xff);
    printf("memory = %uk\n", memory >> 10);
    buf2[sizeof buf2 - 1] = 0;
    u = read_segofs16(vbe_buf + 0x06);
    memcpy(buf2, (void *)u, sizeof buf2 - 1);
    printf("oem name [0x%05x] = \"%s\"\n", u, buf2);
    u = read_segofs16(vbe_buf + 0x16);
    memcpy(buf2, (void *)u, sizeof buf2 - 1);
    printf("vendor name [0x%05x] = \"%s\"\n", u, buf2);
    u = read_segofs16(vbe_buf + 0x1a);
    memcpy(buf2, (void *)u, sizeof buf2 - 1);
    printf("product name [0x%05x] = \"%s\"\n", u, buf2);
    u = read_segofs16(vbe_buf + 0x1e);
    memcpy(buf2, (void *)u, sizeof buf2 - 1);
    printf("product revision [0x%05x] = \"%s\"\n", u, buf2);
  }
  ml = read_segofs16(vbe_buf + 0x0e);
  printf("ml = %d\n", ml);
}


x86 assembly (clang, -O0):
<print_vbe_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5d0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x4(%rax),%eax
mov    %eax,-0x584(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x14(%rax),%eax
mov    %eax,-0x588(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x12(%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x58c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12ee <print_vbe_info+0x1be>
mov    -0x584(%rbp),%esi
shr    $0x8,%esi
mov    -0x584(%rbp),%edx
and    $0xff,%edx
mov    -0x588(%rbp),%ecx
shr    $0x8,%ecx
mov    -0x588(%rbp),%r8d
and    $0xff,%r8d
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58c(%rbp),%esi
shr    $0xa,%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x6,%rdi
call   1030 <read_segofs16@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%eax
mov    %eax,%esi
mov    $0xff,%edx
call   1050 <memcpy@plt>
mov    -0x114(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x16,%rdi
call   1030 <read_segofs16@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%eax
mov    %eax,%esi
mov    $0xff,%edx
call   1050 <memcpy@plt>
mov    -0x114(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x1a,%rdi
call   1030 <read_segofs16@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%eax
mov    %eax,%esi
mov    $0xff,%edx
call   1050 <memcpy@plt>
mov    -0x114(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x1e,%rdi
call   1030 <read_segofs16@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%eax
mov    %eax,%esi
mov    $0xff,%edx
call   1050 <memcpy@plt>
mov    -0x114(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0xe,%rdi
call   1030 <read_segofs16@plt>
mov    %eax,-0x118(%rbp)
mov    -0x118(%rbp),%esi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x5d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_vbe_info>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
movzbl 0x12(%rdi),%ebp
shl    $0x6,%ebp
movzbl 0x14(%rdi),%r8d
movzbl 0x4(%rdi),%edx
lea    0xeab(%rip),%rdi
xor    %esi,%esi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,0xff(%rsp)
lea    0x6(%rbx),%rdi
call   1030 <read_segofs16@plt>
mov    %eax,%ebp
mov    %eax,%esi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0xe98(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x16(%rbx),%rdi
call   1030 <read_segofs16@plt>
mov    %eax,%ebp
mov    %eax,%esi
mov    %r14,%rdi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0xe85(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1a(%rbx),%rdi
call   1030 <read_segofs16@plt>
mov    %eax,%ebp
mov    %eax,%esi
mov    %r14,%rdi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0xe75(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1e(%rbx),%rdi
call   1030 <read_segofs16@plt>
mov    %eax,%ebp
mov    %eax,%esi
mov    %r14,%rdi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0xe66(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xe,%rbx
mov    %rbx,%rdi
call   1030 <read_segofs16@plt>
lea    0xe69(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"version = %u.%u, oem version = %u.%u\0A\00"
@.str.1 = [14 x i8] c"memory = %uk\0A\00"
@.str.2 = [26 x i8] c"oem name [0x%05x] = \22%s\22\0A\00"
@.str.3 = [29 x i8] c"vendor name [0x%05x] = \22%s\22\0A\00"
@.str.4 = [30 x i8] c"product name [0x%05x] = \22%s\22\0A\00"
@.str.5 = [34 x i8] c"product revision [0x%05x] = \22%s\22\0A\00"
@.str.6 = [9 x i8] c"ml = %d\0A\00"
define void @print_vbe_info(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca [64 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
store i32 %33, i32* %13
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i64 20
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
store i32 %37, i32* %14
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 18
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 16
store i32 %42, i32* %15
%43 = load i32, i32* %3
%44 = icmp ne i32 %43, 0
br i1 %44, label %103, label %45
45: ; preds = %1
%46 = load i32, i32* %13
%47 = lshr i32 %46, 8
%48 = load i32, i32* %13
%49 = and i32 %48, 255
%50 = load i32, i32* %14
%51 = lshr i32 %50, 8
%52 = load i32, i32* %14
%53 = and i32 %52, 255
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %49, i32 %51, i32 %53)
%55 = load i32, i32* %15
%56 = lshr i32 %55, 10
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
store i8 0, i8* %58
%59 = load i8*, i8** %2
%60 = getelementptr inbounds i8, i8* %59, i64 6
%61 = call i32 @read_segofs16(i8* %60)
store i32 %61, i32* %5
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%63 = load i32, i32* %5
%64 = zext i32 %63 to i64
%65 = inttoptr i64 %64 to i8*
%66 = call i32 @memcpy(i8* %62, i8* %65, i32 255)
%67 = load i32, i32* %5
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%69 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %67, i8* %68)
%70 = load i8*, i8** %2
%71 = getelementptr inbounds i8, i8* %70, i64 22
%72 = call i32 @read_segofs16(i8* %71)
store i32 %72, i32* %5
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%74 = load i32, i32* %5
%75 = zext i32 %74 to i64
%76 = inttoptr i64 %75 to i8*
%77 = call i32 @memcpy(i8* %73, i8* %76, i32 255)
%78 = load i32, i32* %5
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %78, i8* %79)
%81 = load i8*, i8** %2
%82 = getelementptr inbounds i8, i8* %81, i64 26
%83 = call i32 @read_segofs16(i8* %82)
store i32 %83, i32* %5
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%85 = load i32, i32* %5
%86 = zext i32 %85 to i64
%87 = inttoptr i64 %86 to i8*
%88 = call i32 @memcpy(i8* %84, i8* %87, i32 255)
%89 = load i32, i32* %5
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%91 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %89, i8* %90)
%92 = load i8*, i8** %2
%93 = getelementptr inbounds i8, i8* %92, i64 30
%94 = call i32 @read_segofs16(i8* %93)
store i32 %94, i32* %5
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%96 = load i32, i32* %5
%97 = zext i32 %96 to i64
%98 = inttoptr i64 %97 to i8*
%99 = call i32 @memcpy(i8* %95, i8* %98, i32 255)
%100 = load i32, i32* %5
%101 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%102 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %100, i8* %101)
br label %103
103: ; preds = %45, %1
%104 = load i8*, i8** %2
%105 = getelementptr inbounds i8, i8* %104, i64 14
%106 = call i32 @read_segofs16(i8* %105)
store i32 %106, i32* %6
%107 = load i32, i32* %6
%108 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %107)
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"version = %u.%u, oem version = %u.%u\0A\00"
@.str.1 = [14 x i8] c"memory = %uk\0A\00"
@.str.2 = [26 x i8] c"oem name [0x%05x] = \22%s\22\0A\00"
@.str.3 = [29 x i8] c"vendor name [0x%05x] = \22%s\22\0A\00"
@.str.4 = [30 x i8] c"product name [0x%05x] = \22%s\22\0A\00"
@.str.5 = [34 x i8] c"product revision [0x%05x] = \22%s\22\0A\00"
@.str.6 = [9 x i8] c"ml = %d\0A\00"
define void @print_vbe_info(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds i8, i8* %0, i64 18
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = shl nuw nsw i32 %6, 6
%8 = getelementptr inbounds i8, i8* %0, i64 20
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = getelementptr inbounds i8, i8* %0, i64 4
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 0, i32 %13, i32 0, i32 %10)
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
store i8 0, i8* %16
%17 = getelementptr inbounds i8, i8* %0, i64 6
%18 = tail call i32 @read_segofs16(i8* %17)
%19 = zext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @memcpy(i8* %3, i8* %20, i32 255)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %3)
%23 = getelementptr inbounds i8, i8* %0, i64 22
%24 = call i32 @read_segofs16(i8* %23)
%25 = zext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = call i32 @memcpy(i8* %3, i8* %26, i32 255)
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %3)
%29 = getelementptr inbounds i8, i8* %0, i64 26
%30 = call i32 @read_segofs16(i8* %29)
%31 = zext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
%33 = call i32 @memcpy(i8* %3, i8* %32, i32 255)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %3)
%35 = getelementptr inbounds i8, i8* %0, i64 30
%36 = call i32 @read_segofs16(i8* %35)
%37 = zext i32 %36 to i64
%38 = inttoptr i64 %37 to i8*
%39 = call i32 @memcpy(i8* %3, i8* %38, i32 255)
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %36, i8* %3)
%41 = getelementptr inbounds i8, i8* %0, i64 14
%42 = call i32 @read_segofs16(i8* %41)
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %42)
ret void
}