#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int get_cpu_type(void) {
  FILE *fd;
  char line[256];
  int found = 0;
  if ((fd = fopen("/proc/cpuinfo", "r")) == NULL) {
    printf("Can't open /proc/cpuinfo\n");
    return -1;
  }
  while (fgets(line, 120, fd) != NULL) {
    if (strncmp(line, "Hardware", 8) == 0) {
      found = 1;
      break;
    }
  }
  if (!found) {
    printf("Can't find hardware type!\n");
    return -1;
  }
  if (strstr(line, "BCM2709") != NULL)
    return 1;
  else if (strstr(line, "BCM2708") != NULL)
    return 0;
  else {
    printf("Unknown hardware type %s\n", line);
    return -1;
  }
}


x86 assembly (clang, -O0):
<get_cpu_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x114(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a0 <get_cpu_type+0x50>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <get_cpu_type+0x13f>
jmp    11a5 <get_cpu_type+0x55>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x78,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fa <get_cpu_type+0xaa>
lea    -0x110(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f5 <get_cpu_type+0xa5>
movl   $0x1,-0x114(%rbp)
jmp    11fa <get_cpu_type+0xaa>
jmp    11a5 <get_cpu_type+0x55>
cmpl   $0x0,-0x114(%rbp)
jne    1221 <get_cpu_type+0xd1>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <get_cpu_type+0x13f>
lea    -0x110(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     124a <get_cpu_type+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    128f <get_cpu_type+0x13f>
lea    -0x110(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1273 <get_cpu_type+0x123>
movl   $0x0,-0x4(%rbp)
jmp    128f <get_cpu_type+0x13f>
lea    -0x110(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_type>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xee7(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1212 <get_cpu_type+0xb2>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe6d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x78,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     121b <get_cpu_type+0xbb>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11a0 <get_cpu_type+0x40>
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    122c <get_cpu_type+0xcc>
lea    0xe26(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    122c <get_cpu_type+0xcc>
lea    0xe15(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1227 <get_cpu_type+0xc7>
lea    0xe36(%rip),%rdi
jmp    1222 <get_cpu_type+0xc2>
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Can't open /proc/cpuinfo\0A\00"
@.str.3 = [9 x i8] c"Hardware\00"
@.str.4 = [27 x i8] c"Can't find hardware type!\0A\00"
@.str.5 = [8 x i8] c"BCM2709\00"
@.str.6 = [8 x i8] c"BCM2708\00"
@.str.7 = [26 x i8] c"Unknown hardware type %s\0A\00"
define i32 @get_cpu_type() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32
store i32 0, i32* %4
%5 = 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* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %39
9: ; preds = %0
br label %10
10: ; preds = %20, %9
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32* @fgets(i8* %11, i32 120, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %4
br label %21
20: ; preds = %15
br label %10
21: ; preds = %19, %10
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %39
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = call i32* @strstr(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 1, i32* %1
br label %39
31: ; preds = %26
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = call i32* @strstr(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 0, i32* %1
br label %39
36: ; preds = %31
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %37)
store i32 -1, i32* %1
br label %39
39: ; preds = %36, %35, %30, %24, %7
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"Hardware\00"
@.str.5 = [8 x i8] c"BCM2709\00"
@.str.6 = [8 x i8] c"BCM2708\00"
@.str.7 = [26 x i8] c"Unknown hardware type %s\0A\00"
@str = [26 x i8] c"Can't find hardware type!\00"
@str.8 = [25 x i8] c"Can't open /proc/cpuinfo\00"
define i32 @get_cpu_type() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
br label %23
7: ; preds = %0, %10
%8 = call i32* @fgets(i8* %2, i32 120, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %7
13: ; preds = %7
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %23
15: ; preds = %10
%16 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %2)
br label %23
23: ; preds = %18, %15, %21, %13, %5
%24 = phi i32 [ -1, %5 ], [ -1, %21 ], [ -1, %13 ], [ 1, %15 ], [ 0, %18 ]
ret i32 %24
}