#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*/ buf;
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 *strstr(char *, char *);
int boardType(void) {
  FILE *fp;
  char buf[1024], *ptr;
  int n, board = 1;
  if ((fp = fopen("/proc/cmdline", "r"))) {
    while (fgets(buf, sizeof(buf), fp)) {
      if ((ptr = strstr(buf, "mem_size=")) &&
          (sscanf(&ptr[9], "%x", &n) == 1) && (n == 0x3F000000)) {
        board = 2;
        break;
      } else if ((ptr = strstr(buf, "boardrev=")) &&
                 (sscanf(&ptr[9], "%x", &n) == 1) &&
                 ((n == 0x02) || (n == 0x03))) {
        board = 0;
        break;
      }
    }
    fclose(fp);
  }
  return board;
}


x86 assembly (clang, -O0):
<boardType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x1,-0x420(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     129b <boardType+0x14b>
jmp    118b <boardType+0x3b>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1292 <boardType+0x142>
lea    -0x410(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     1214 <boardType+0xc4>
mov    -0x418(%rbp),%rdi
add    $0x9,%rdi
lea    0xe3a(%rip),%rsi
lea    -0x41c(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1214 <boardType+0xc4>
cmpl   $0x3f000000,-0x41c(%rbp)
jne    1214 <boardType+0xc4>
movl   $0x2,-0x420(%rbp)
jmp    1292 <boardType+0x142>
lea    -0x410(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     1288 <boardType+0x138>
mov    -0x418(%rbp),%rdi
add    $0x9,%rdi
lea    0xdd0(%rip),%rsi
lea    -0x41c(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1288 <boardType+0x138>
cmpl   $0x2,-0x41c(%rbp)
je     1279 <boardType+0x129>
cmpl   $0x3,-0x41c(%rbp)
jne    1288 <boardType+0x138>
movl   $0x0,-0x420(%rbp)
jmp    1292 <boardType+0x142>
jmp    128d <boardType+0x13d>
jmp    118b <boardType+0x3b>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x420(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<boardType>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     124d <boardType+0xfd>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1260 <boardType+0x110>
lea    0xe69(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xe6a(%rip),%r12
lea    0xe60(%rip),%r13
lea    0xc(%rsp),%r14
jmp    11e5 <boardType+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1254 <boardType+0x104>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1216 <boardType+0xc6>
add    $0x9,%rax
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1216 <boardType+0xc6>
cmpl   $0x3f000000,0xc(%rsp)
3f
je     125b <boardType+0x10b>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11d0 <boardType+0x80>
add    $0x9,%rax
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11d0 <boardType+0x80>
mov    0xc(%rsp),%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11d0 <boardType+0x80>
xor    %ebp,%ebp
jmp    1260 <boardType+0x110>
mov    $0x1,%ebp
jmp    1268 <boardType+0x118>
mov    $0x1,%ebp
jmp    1260 <boardType+0x110>
mov    $0x2,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x418,%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 = [10 x i8] c"mem_size=\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [10 x i8] c"boardrev=\00"
define i32 @boardType() {
%1 = alloca i32*
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 1, i32* %5
%6 = 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* %6, i32** %1
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %48
8: ; preds = %0
br label %9
9: ; preds = %44, %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 9
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1056964608
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 2, i32* %5
br label %45
27: ; preds = %23, %18, %14
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%29 = call i8* @strstr(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i8* %29, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 9
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 2
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %43
42: ; preds = %39, %36
store i32 0, i32* %5
br label %45
43: ; preds = %39, %31, %27
br label %44
44: ; preds = %43
br label %9
45: ; preds = %42, %26, %9
%46 = load i32*, i32** %1
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %0
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"mem_size=\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [10 x i8] c"boardrev=\00"
define i32 @boardType() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %37, label %7
7: ; preds = %0
%8 = call i64 @fgets(i8* %3, i32 1024, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %34, label %10
10: ; preds = %7, %31
%11 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 9
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%16 = icmp eq i32 %15, 1
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 1056964608
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %34, label %20
20: ; preds = %13, %10
%21 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 9
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %2
%29 = and i32 %28, -2
%30 = icmp eq i32 %29, 2
br i1 %30, label %34, label %31
31: ; preds = %20, %23, %27
%32 = call i64 @fgets(i8* %3, i32 1024, i32* %5)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %10
34: ; preds = %31, %13, %27, %7
%35 = phi i32 [ 1, %7 ], [ 0, %27 ], [ 2, %13 ], [ 1, %31 ]
%36 = call i32 @fclose(i32* %5)
br label %37
37: ; preds = %34, %0
%38 = phi i32 [ %35, %34 ], [ 1, %0 ]
ret i32 %38
}