#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, int *);
char *strsep(char **, char *);
char *strstr(char *, char *);
int get_fb_mode() {
  FILE *f;
  char buf[256], *s, *t;
  int i, fb_mode = 0;
  if ((f = fopen("/proc/cmdline", "r"))) {
    if (fgets(buf, sizeof buf, f)) {
      t = buf;
      while ((s = strsep(&t, " "))) {
        if (sscanf(s, "vga=%i", &i) == 1)
          fb_mode = i;
        if (strstr(s, "vga=normal") == s)
          fb_mode = 0;
      }
    }
    fclose(f);
  }
  return fb_mode > 0x10 ? fb_mode : 0;
}


x86 assembly (clang, -O0):
<get_fb_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x128(%rbp)
lea    0xe84(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1253 <get_fb_mode+0xf3>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     124a <get_fb_mode+0xea>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     1245 <get_fb_mode+0xe5>
mov    -0x118(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    -0x124(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1216 <get_fb_mode+0xb6>
mov    -0x124(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x118(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1080 <strstr@plt>
cmp    -0x118(%rbp),%rax
jne    1240 <get_fb_mode+0xe0>
movl   $0x0,-0x128(%rbp)
jmp    11c3 <get_fb_mode+0x63>
jmp    124a <get_fb_mode+0xea>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x10,-0x128(%rbp)
jle    1271 <get_fb_mode+0x111>
mov    -0x128(%rbp),%eax
mov    %eax,-0x12c(%rbp)
jmp    127e <get_fb_mode+0x11e>
xor    %eax,%eax
mov    %eax,-0x12c(%rbp)
jmp    127e <get_fb_mode+0x11e>
mov    -0x12c(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fb_mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1266 <get_fb_mode+0x106>
mov    %rax,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1247 <get_fb_mode+0xe7>
mov    %rbp,0x10(%rsp)
lea    0xe53(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strsep@plt>
test   %rax,%rax
je     1247 <get_fb_mode+0xe7>
mov    %rax,%rbp
mov    %rbx,0x18(%rsp)
xor    %r15d,%r15d
lea    0xc(%rsp),%r12
lea    0xe36(%rip),%r13
lea    0xe26(%rip),%rbx
lea    0x10(%rsp),%r14
jmp    1229 <get_fb_mode+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
cmove  %eax,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strsep@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1251 <get_fb_mode+0xf1>
mov    %rbp,%rdi
lea    0xddf(%rip),%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1200 <get_fb_mode+0xa0>
mov    0xc(%rsp),%r15d
jmp    1200 <get_fb_mode+0xa0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1266 <get_fb_mode+0x106>
mov    0x18(%rsp),%rdi
call   1040 <fclose@plt>
xor    %r14d,%r14d
cmp    $0x11,%r15d
cmovge %r15d,%r14d
mov    %r14d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c"vga=%i\00"
@.str.4 = [11 x i8] c"vga=normal\00"
define i32 @get_fb_mode() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %6
%7 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %1
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %36
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i64 @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8* %15, i8** %4
br label %16
16: ; preds = %31, %14
%17 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i32, i32* %5
store i32 %24, i32* %6
br label %25
25: ; preds = %23, %19
%26 = load i8*, i8** %3
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%28 = load i8*, i8** %3
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %6
br label %31
31: ; preds = %30, %25
br label %16
32: ; preds = %16
br label %33
33: ; preds = %32, %9
%34 = load i32*, i32** %1
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %0
%37 = load i32, i32* %6
%38 = icmp sgt i32 %37, 16
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = load i32, i32* %6
br label %42
41: ; preds = %36
br label %42
42: ; preds = %41, %39
%43 = phi i32 [ %40, %39 ], [ 0, %41 ]
ret i32 %43
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c"vga=%i\00"
@.str.4 = [11 x i8] c"vga=normal\00"
define i32 @get_fb_mode() {
%1 = alloca [256 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %0
%10 = call i64 @fgets(i8* %4, i32 256, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %9
store i8* %4, i8** %2
%13 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %31, label %15
15: ; preds = %12, %15
%16 = phi i8* [ %25, %15 ], [ %13, %12 ]
%17 = phi i32 [ %24, %15 ], [ 0, %12 ]
%18 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
%20 = load i32, i32* %3
%21 = select i1 %19, i32 %20, i32 %17
%22 = call i32 @strncmp(i8* %16, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 10)
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i32 0, i32 %21
%25 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %15
27: ; preds = %15
%28 = call i32 @fclose(i32* %7)
%29 = icmp sgt i32 %24, 16
%30 = select i1 %29, i32 %24, i32 0
br label %33
31: ; preds = %12, %9
%32 = call i32 @fclose(i32* %7)
br label %33
33: ; preds = %27, %31, %0
%34 = phi i32 [ 0, %0 ], [ %30, %27 ], [ 0, %31 ]
ret i32 %34
}