#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 FS460_get_available_vga_modes(unsigned long *);
int FS460_get_vga_mode(unsigned long *);
int FS460_set_vga_mode(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
char *str_VgaMode(unsigned long);
scalar_t__ strcmp(char *, char *);
void vga_mode(char *mod) {
  int err;
  unsigned long vga_mode, available_vga_modes;
  err = FS460_get_vga_mode(&vga_mode);
  if (err) {
    printf("error %u getting vga mode.\n", err);
    return;
  }
  err = FS460_get_available_vga_modes(&available_vga_modes);
  if (err) {
    printf("error %u getting available vga modes.\n", err);
    return;
  }
  if (available_vga_modes) {
    if (0 == strcmp(mod, "+")) {
      do {
        vga_mode <<= 1;
        if (!vga_mode)
          vga_mode = 1;
      } while (!(vga_mode & available_vga_modes));
    } else if (0 == strcmp(mod, "-")) {
      do {
        vga_mode >>= 1;
        if (!vga_mode)
          vga_mode = 0x80000000;
      } while (!(vga_mode & available_vga_modes));
    } else if (0 == strcmp(mod, "")) {
    } else {
      printf("Invalid command.\n");
      return;
    }
    err = FS460_set_vga_mode(vga_mode);
    if (err)
      printf("error %u setting vga mode.\n", err);
    else {
      err = FS460_get_vga_mode(&vga_mode);
      if (err)
        printf("error %u getting vga mode after set.\n", err);
      else
        printf("  vga mode=%s\n", str_VgaMode(vga_mode));
    }
  }
}


x86 assembly (clang, -O0):
<vga_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <FS460_get_vga_mode@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1198 <vga_mode+0x38>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1356 <vga_mode+0x1f6>
lea    -0x20(%rbp),%rdi
call   1030 <FS460_get_available_vga_modes@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c4 <vga_mode+0x64>
mov    -0xc(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1356 <vga_mode+0x1f6>
cmpq   $0x0,-0x20(%rbp)
je     1356 <vga_mode+0x1f6>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1234 <vga_mode+0xd4>
jmp    11f2 <vga_mode+0x92>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1211 <vga_mode+0xb1>
movq   $0x1,-0x18(%rbp)
jmp    1216 <vga_mode+0xb6>
mov    -0x18(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f2 <vga_mode+0x92>
jmp    12da <vga_mode+0x17a>
mov    -0x8(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    129a <vga_mode+0x13a>
jmp    1257 <vga_mode+0xf7>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1277 <vga_mode+0x117>
mov    $0x80000000,%eax
mov    %rax,-0x18(%rbp)
jmp    127c <vga_mode+0x11c>
mov    -0x18(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1257 <vga_mode+0xf7>
jmp    12d5 <vga_mode+0x175>
mov    -0x8(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12bd <vga_mode+0x15d>
jmp    12d0 <vga_mode+0x170>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1356 <vga_mode+0x1f6>
jmp    12d5 <vga_mode+0x175>
jmp    12da <vga_mode+0x17a>
mov    -0x18(%rbp),%rdi
call   1080 <FS460_set_vga_mode@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1306 <vga_mode+0x1a6>
mov    -0xc(%rbp),%esi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1351 <vga_mode+0x1f1>
lea    -0x18(%rbp),%rdi
call   1050 <FS460_get_vga_mode@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1332 <vga_mode+0x1d2>
mov    -0xc(%rbp),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    134c <vga_mode+0x1ec>
mov    -0x18(%rbp),%rdi
call   1040 <str_VgaMode@plt>
mov    %rax,%rsi
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1351 <vga_mode+0x1f1>
jmp    1356 <vga_mode+0x1f6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vga_mode>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1060 <FS460_get_vga_mode@plt>
test   %eax,%eax
je     118d <vga_mode+0x1d>
lea    0xe75(%rip),%rdi
jmp    11a2 <vga_mode+0x32>
lea    0x8(%rsp),%rdi
call   1030 <FS460_get_available_vga_modes@plt>
test   %eax,%eax
je     11b1 <vga_mode+0x41>
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
cmpq   $0x0,0x8(%rsp)
je     11ab <vga_mode+0x3b>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1207 <vga_mode+0x97>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     122e <vga_mode+0xbe>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1287 <vga_mode+0x117>
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
jmp    11ab <vga_mode+0x3b>
mov    0x8(%rsp),%rax
mov    (%rsp),%rdi
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
add    %rdi,%rdi
cmove  %rcx,%rdi
test   %rax,%rdi
je     1220 <vga_mode+0xb0>
jmp    1256 <vga_mode+0xe6>
mov    0x8(%rsp),%rax
mov    (%rsp),%rdi
mov    $0x80000000,%ecx
nopl   0x0(%rax)
mov    %rdi,%rdx
shr    %rdx
cmp    $0x2,%rdi
mov    %rdx,%rdi
cmovb  %rcx,%rdi
test   %rax,%rdi
je     1240 <vga_mode+0xd0>
mov    %rdi,(%rsp)
call   1090 <FS460_set_vga_mode@plt>
test   %eax,%eax
je     126f <vga_mode+0xff>
lea    0xddd(%rip),%rdi
jmp    11a2 <vga_mode+0x32>
mov    %rsp,%rdi
call   1060 <FS460_get_vga_mode@plt>
test   %eax,%eax
je     128d <vga_mode+0x11d>
lea    0xde1(%rip),%rdi
jmp    11a2 <vga_mode+0x32>
mov    (%rsp),%rdi
jmp    125a <vga_mode+0xea>
mov    (%rsp),%rdi
call   1050 <str_VgaMode@plt>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11ab <vga_mode+0x3b>

LLVM IR (-O0):
@.str = [28 x i8] c"error %u getting vga mode.\0A\00"
@.str.1 = [39 x i8] c"error %u getting available vga modes.\0A\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [18 x i8] c"Invalid command.\0A\00"
@.str.6 = [28 x i8] c"error %u setting vga mode.\0A\00"
@.str.7 = [38 x i8] c"error %u getting vga mode after set.\0A\00"
@.str.8 = [15 x i8] c" vga mode=%s\0A\00"
define void @vga_mode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = call i32 @FS460_get_vga_mode(i64* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %90
12: ; preds = %1
%13 = call i32 @FS460_get_available_vga_modes(i64* %5)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %90
19: ; preds = %12
%20 = load i64, i64* %5
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %90
22: ; preds = %19
%23 = load i8*, i8** %2
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %41
26: ; preds = %22
br label %27
27: ; preds = %34, %26
%28 = load i64, i64* %4
%29 = shl i64 %28, 1
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = icmp ne i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
store i64 1, i64* %4
br label %33
33: ; preds = %32, %27
br label %34
34: ; preds = %33
%35 = load i64, i64* %4
%36 = load i64, i64* %5
%37 = and i64 %35, %36
%38 = icmp ne i64 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %27, label %40
40: ; preds = %34
br label %69
41: ; preds = %22
%42 = load i8*, i8** %2
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 0, %43
br i1 %44, label %45, label %60
45: ; preds = %41
br label %46
46: ; preds = %53, %45
%47 = load i64, i64* %4
%48 = lshr i64 %47, 1
store i64 %48, i64* %4
%49 = load i64, i64* %4
%50 = icmp ne i64 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %46
store i64 2147483648, i64* %4
br label %52
52: ; preds = %51, %46
br label %53
53: ; preds = %52
%54 = load i64, i64* %4
%55 = load i64, i64* %5
%56 = and i64 %54, %55
%57 = icmp ne i64 %56, 0
%58 = xor i1 %57, true
br i1 %58, label %46, label %59
59: ; preds = %53
br label %68
60: ; preds = %41
%61 = load i8*, i8** %2
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%63 = icmp eq i64 0, %62
br i1 %63, label %64, label %65
64: ; preds = %60
br label %67
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %90
67: ; preds = %64
br label %68
68: ; preds = %67, %59
br label %69
69: ; preds = %68, %40
%70 = load i64, i64* %4
%71 = call i32 @FS460_set_vga_mode(i64 %70)
store i32 %71, i32* %3
%72 = load i32, i32* %3
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i32, i32* %3
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %75)
br label %89
77: ; preds = %69
%78 = call i32 @FS460_get_vga_mode(i64* %4)
store i32 %78, i32* %3
%79 = load i32, i32* %3
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %77
%82 = load i32, i32* %3
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %82)
br label %88
84: ; preds = %77
%85 = load i64, i64* %4
%86 = call i8* @str_VgaMode(i64 %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %84, %81
br label %89
89: ; preds = %88, %74
br label %90
90: ; preds = %9, %16, %65, %89, %19
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"error %u getting vga mode.\0A\00"
@.str.1 = [39 x i8] c"error %u getting available vga modes.\0A\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.6 = [28 x i8] c"error %u setting vga mode.\0A\00"
@.str.7 = [38 x i8] c"error %u getting vga mode after set.\0A\00"
@.str.8 = [15 x i8] c" vga mode=%s\0A\00"
@str = [17 x i8] c"Invalid command.\00"
define void @vga_mode(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @FS460_get_vga_mode(i64* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %68
10: ; preds = %1
%11 = call i32 @FS460_get_available_vga_modes(i64* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %68
15: ; preds = %10
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %68, label %18
18: ; preds = %15
%19 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i64, i64* %3
%23 = load i64, i64* %2
br label %24
24: ; preds = %21, %24
%25 = phi i64 [ %23, %21 ], [ %28, %24 ]
%26 = shl i64 %25, 1
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i64 1, i64 %26
%29 = and i64 %28, %22
%30 = icmp eq i64 %29, 0
br i1 %30, label %24, label %51
31: ; preds = %18
%32 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i64, i64* %3
%36 = load i64, i64* %2
br label %37
37: ; preds = %34, %37
%38 = phi i64 [ %36, %34 ], [ %41, %37 ]
%39 = lshr i64 %38, 1
%40 = icmp ult i64 %38, 2
%41 = select i1 %40, i64 2147483648, i64 %39
%42 = and i64 %41, %35
%43 = icmp eq i64 %42, 0
br i1 %43, label %37, label %52
44: ; preds = %31
%45 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load i64, i64* %2
br label %53
49: ; preds = %44
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %68
51: ; preds = %24
store i64 %28, i64* %2
br label %53
52: ; preds = %37
store i64 %41, i64* %2
br label %53
53: ; preds = %47, %52, %51
%54 = phi i64 [ %48, %47 ], [ %41, %52 ], [ %28, %51 ]
%55 = call i32 @FS460_set_vga_mode(i64 %54)
%56 = icmp eq i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %55)
br label %68
59: ; preds = %53
%60 = call i32 @FS460_get_vga_mode(i64* %2)
%61 = icmp eq i32 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %60)
br label %68
64: ; preds = %59
%65 = load i64, i64* %2
%66 = call i8* @str_VgaMode(i64 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %15, %62, %64, %57, %49, %13, %8
ret void
}