#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 */
struct fb_var_screeninfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
int /*<<< orphan*/ FBIOPUT_VSCREENINFO;
int /*<<< orphan*/ O_RDWR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_var(struct fb_var_screeninfo *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_var(struct fb_var_screeninfo *, int, int, int, int, int,
                           int);
int main(int argc, char **argv) {
  int fd = 0;
  struct fb_var_screeninfo vinfo;
  int ret = 0;
  int just_read = 0;
  int hbp, hfp, hsw;
  int vbp, vfp, vsw;
  if (argc == 1) {
    just_read = 1;
  } else if (argc != 7) {
    printf("usage: ./setfb HBP HFP HSW VBP VFP VSW\n");
    return 1;
  }
  fd = open("/dev/fb0", O_RDWR);
  if (fd < 0) {
    printf("Error: cannot open framebuffer device.\n");
    exit(3);
  }
  if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
    printf("Error reading variable information.\n");
    close(fd);
    exit(4);
  }
  print_var(&vinfo);
  if (just_read)
    goto L_OUT;
  hbp = atoi(argv[1]);
  hfp = atoi(argv[2]);
  hsw = atoi(argv[3]);
  vbp = atoi(argv[4]);
  vfp = atoi(argv[5]);
  vsw = atoi(argv[6]);
  set_var(&vinfo, hbp, hfp, hsw, vbp, vfp, vsw);
  ret = ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo);
  if (ret) {
    perror("set to vga failed");
  } else
    print_var(&vinfo);
L_OUT:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d1 <main+0x41>
movl   $0x1,-0x20(%rbp)
jmp    11f8 <main+0x68>
cmpl   $0x7,-0x8(%rbp)
je     11f3 <main+0x63>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1353 <main+0x1c3>
jmp    11f8 <main+0x68>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1230 <main+0xa0>
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%eax
jge    126c <main+0xdc>
lea    0xe04(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1070 <print_var@plt>
cmpl   $0x0,-0x20(%rbp)
je     1284 <main+0xf4>
jmp    1345 <main+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x34(%rbp),%r9d
mov    -0x38(%rbp),%eax
lea    -0x18(%rbp),%rdi
mov    %eax,(%rsp)
call   1050 <set_var@plt>
mov    -0x14(%rbp),%edi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1337 <main+0x1a7>
lea    0xd51(%rip),%rdi
call   1090 <perror@plt>
jmp    1340 <main+0x1b0>
lea    -0x18(%rbp),%rdi
call   1070 <print_var@plt>
jmp    1345 <main+0x1b5>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
cmp    $0x1,%edi
je     11b1 <main+0x21>
cmp    $0x7,%ebx
jne    1297 <main+0x107>
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12ce <main+0x13e>
mov    %eax,%r15d
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
js     12e4 <main+0x154>
lea    0x8(%rsp),%rdi
call   1070 <print_var@plt>
xor    %r14d,%r14d
cmp    $0x1,%ebx
je     128d <main+0xfd>
mov    0x8(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    0x18(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    0x20(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
mov    0x28(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r13d
mov    0x30(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,(%rsp)
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %ebx,%ecx
mov    %r12d,%r8d
mov    %r13d,%r9d
call   1050 <set_var@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
jne    12bb <main+0x12b>
lea    0x8(%rsp),%rdi
call   1070 <print_var@plt>
mov    %r15d,%edi
call   1060 <close@plt>
jmp    12a9 <main+0x119>
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xd45(%rip),%rdi
call   1090 <perror@plt>
mov    %ebx,%r14d
jmp    128d <main+0xfd>
lea    0xd6a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
lea    0xd30(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.fb_var_screeninfo = type { i32 }
@.str = [40 x i8] c"usage: ./setfb HBP HFP HSW VBP VFP VSW\0A\00"
@.str.1 = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@.str.2 = [40 x i8] c"Error: cannot open framebuffer device.\0A\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.3 = [37 x i8] c"Error reading variable information.\0A\00"
@FBIOPUT_VSCREENINFO = global i32 0
@.str.4 = [18 x i8] c"set to vga failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.fb_var_screeninfo
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %9
br label %25
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 7
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %94
24: ; preds = %19
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 3)
unreachable
33: ; preds = %25
%34 = load i32, i32* %6
%35 = load i32, i32* @FBIOGET_VSCREENINFO
%36 = call i32 @ioctl(i32 %34, i32 %35, %struct.fb_var_screeninfo* %7)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = call i32 @exit(i32 4)
unreachable
43: ; preds = %33
%44 = call i32 @print_var(%struct.fb_var_screeninfo* %7)
%45 = load i32, i32* %9
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
br label %90
48: ; preds = %43
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %10
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
store i32 %56, i32* %11
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 @atoi(i8* %59)
store i32 %60, i32* %12
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 4
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %13
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 5
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
store i32 %68, i32* %14
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 6
%71 = load i8*, i8** %70
%72 = call i32 @atoi(i8* %71)
store i32 %72, i32* %15
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = load i32, i32* %12
%76 = load i32, i32* %13
%77 = load i32, i32* %14
%78 = load i32, i32* %15
%79 = call i32 @set_var(%struct.fb_var_screeninfo* %7, i32 %73, i32 %74, i32 %75, i32 %76, i32 %77, i32 %78)
%80 = load i32, i32* %6
%81 = load i32, i32* @FBIOPUT_VSCREENINFO
%82 = call i32 @ioctl(i32 %80, i32 %81, %struct.fb_var_screeninfo* %7)
store i32 %82, i32* %8
%83 = load i32, i32* %8
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %48
%86 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %89
87: ; preds = %48
%88 = call i32 @print_var(%struct.fb_var_screeninfo* %7)
br label %89
89: ; preds = %87, %85
br label %90
90: ; preds = %89, %47
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %8
store i32 %93, i32* %3
br label %94
94: ; preds = %90, %22
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
%struct.fb_var_screeninfo = type { i32 }
@.str.1 = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@FBIOGET_VSCREENINFO = global i32 0
@FBIOPUT_VSCREENINFO = global i32 0
@.str.4 = [18 x i8] c"set to vga failed\00"
@str = [36 x i8] c"Error reading variable information.\00"
@str.5 = [39 x i8] c"Error: cannot open framebuffer device.\00"
@str.6 = [39 x i8] c"usage: ./setfb HBP HFP HSW VBP VFP VSW\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.fb_var_screeninfo
%4 = bitcast %struct.fb_var_screeninfo* %3 to i8*
%5 = icmp eq i32 %0, 1
switch i32 %0, label %6 [
i32 7, label %8
i32 1, label %8
]
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
br label %55
8: ; preds = %2, %2
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 @exit(i32 3)
unreachable
15: ; preds = %8
%16 = load i32, i32* @FBIOGET_VSCREENINFO
%17 = call i32 @ioctl(i32 %10, i32 %16, %struct.fb_var_screeninfo* %3)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%21 = call i32 @close(i32 %10)
%22 = call i32 @exit(i32 4)
unreachable
23: ; preds = %15
%24 = call i32 @print_var(%struct.fb_var_screeninfo* %3)
br i1 %5, label %52, label %25
25: ; preds = %23
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = getelementptr inbounds i8*, i8** %1, i64 4
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = getelementptr inbounds i8*, i8** %1, i64 5
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = getelementptr inbounds i8*, i8** %1, i64 6
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = call i32 @set_var(%struct.fb_var_screeninfo* %3, i32 %28, i32 %31, i32 %34, i32 %37, i32 %40, i32 %43)
%45 = load i32, i32* @FBIOPUT_VSCREENINFO
%46 = call i32 @ioctl(i32 %10, i32 %45, %struct.fb_var_screeninfo* %3)
%47 = icmp eq i32 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %25
%49 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %52
50: ; preds = %25
%51 = call i32 @print_var(%struct.fb_var_screeninfo* %3)
br label %52
52: ; preds = %48, %50, %23
%53 = phi i32 [ 0, %23 ], [ %46, %48 ], [ 0, %50 ]
%54 = call i32 @close(i32 %10)
br label %55
55: ; preds = %52, %6
%56 = phi i32 [ %53, %52 ], [ 1, %6 ]
ret i32 %56
}