#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *,
                          unsigned int *, unsigned int *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, unsigned int);
void prepare_videomode() {
  FILE *videomode_file = fopen("/dev/vga/videomode", "r+b");
  unsigned int width, height, bpp;
  fscanf(videomode_file, "%d %d %d", &width, &height, &bpp);
  printf("Current resolution: %dx%d, %d BPP\n", width, height, bpp);
  int n = fprintf(videomode_file, "640 480 8");
  assert(n > 0);
  fclose(videomode_file);
}


x86 assembly (clang, -O0):
<prepare_videomode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1050 <fscanf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fprintf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_videomode>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fprintf@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/dev/vga/videomode\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [35 x i8] c"Current resolution: %dx%d, %d BPP\0A\00"
@.str.4 = [10 x i8] c"640 480 8\00"
define void @prepare_videomode() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = load i32*, i32** %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
%13 = load i32*, i32** %1
%14 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %1
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/dev/vga/videomode\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [35 x i8] c"Current resolution: %dx%d, %d BPP\0A\00"
@.str.4 = [10 x i8] c"640 480 8\00"
define void @prepare_videomode() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
%13 = call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp sgt i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @fclose(i32* %4)
ret void
}