#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*/ dprintf(int, char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int arch_fill_cpuinfo_model(int fd) {
  char buf[1024];
  FILE *fp;
  int ret = -1;
  fp = fopen("/proc/cpuinfo", "r");
  if (fp == NULL)
    return -1;
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    if (!strncmp(buf, "Processor\t:", 11)) {
      dprintf(fd, "cpuinfo:desc=%s", &buf[12]);
      ret = 0;
      break;
    } else if (!strncmp(buf, "model name\t:", 12)) {
      dprintf(fd, "cpuinfo:desc=%s", &buf[13]);
      ret = 0;
      break;
    }
  }
  if (ret < 0)
    dprintf(fd, "cpuinfo:desc=ARM (unknown)\n");
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<arch_fill_cpuinfo_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0x41c(%rbp)
ff ff ff
lea    0xe91(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    119c <arch_fill_cpuinfo_model+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <arch_fill_cpuinfo_model+0x148>
jmp    11a1 <arch_fill_cpuinfo_model+0x51>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1265 <arch_fill_cpuinfo_model+0x115>
lea    -0x410(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    120f <arch_fill_cpuinfo_model+0xbf>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rdx
add    $0xc,%rdx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1050 <dprintf@plt>
movl   $0x0,-0x41c(%rbp)
jmp    1265 <arch_fill_cpuinfo_model+0x115>
lea    -0x410(%rbp),%rdi
lea    0xe0f(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    125b <arch_fill_cpuinfo_model+0x10b>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rdx
add    $0xd,%rdx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1050 <dprintf@plt>
movl   $0x0,-0x41c(%rbp)
jmp    1265 <arch_fill_cpuinfo_model+0x115>
jmp    1260 <arch_fill_cpuinfo_model+0x110>
jmp    11a1 <arch_fill_cpuinfo_model+0x51>
cmpl   $0x0,-0x41c(%rbp)
jge    1283 <arch_fill_cpuinfo_model+0x133>
mov    -0x8(%rbp),%edi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1050 <dprintf@plt>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x41c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arch_fill_cpuinfo_model>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
lea    0xe97(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d4 <arch_fill_cpuinfo_model+0x84>
mov    %rax,%rbx
mov    %rsp,%rbp
lea    0xe89(%rip),%r15
lea    0xe9e(%rip),%r12
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11db <arch_fill_cpuinfo_model+0x8b>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f3 <arch_fill_cpuinfo_model+0xa3>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <arch_fill_cpuinfo_model+0x40>
lea    0xd(%rsp),%rdx
jmp    11f8 <arch_fill_cpuinfo_model+0xa8>
mov    $0xffffffff,%ebp
jmp    1213 <arch_fill_cpuinfo_model+0xc3>
lea    0xe57(%rip),%rsi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <dprintf@plt>
mov    $0xffffffff,%ebp
jmp    120b <arch_fill_cpuinfo_model+0xbb>
lea    0xc(%rsp),%rdx
lea    0xe1d(%rip),%rsi
xor    %ebp,%ebp
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <dprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"Processor\09:\00"
@.str.3 = [16 x i8] c"cpuinfo:desc=%s\00"
@.str.4 = [13 x i8] c"model name\09:\00"
@.str.5 = [28 x i8] c"cpuinfo:desc=ARM (unknown)\0A\00"
define i32 @arch_fill_cpuinfo_model(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i32 -1, 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** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %45
11: ; preds = %1
br label %12
12: ; preds = %34, %11
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = call i32 @strncmp(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* %3
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 12
%24 = call i32 (i32, i8*, ...) @dprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %23)
store i32 0, i32* %6
br label %35
25: ; preds = %17
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = call i32 @strncmp(i8* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* %3
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 13
%32 = call i32 (i32, i8*, ...) @dprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %31)
store i32 0, i32* %6
br label %35
33: ; preds = %25
br label %34
34: ; preds = %33
br label %12
35: ; preds = %29, %21, %12
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* %3
%40 = call i32 (i32, i8*, ...) @dprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %38, %35
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %6
store i32 %44, i32* %2
br label %45
45: ; preds = %41, %10
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"Processor\09:\00"
@.str.3 = [16 x i8] c"cpuinfo:desc=%s\00"
@.str.4 = [13 x i8] c"model name\09:\00"
@.str.5 = [28 x i8] c"cpuinfo:desc=ARM (unknown)\0A\00"
define i32 @arch_fill_cpuinfo_model(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %26, label %6
6: ; preds = %1, %15
%7 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 12
%14 = call i32 (i32, i8*, ...) @dprintf(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %13)
br label %23
15: ; preds = %9
%16 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %15
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 13
%20 = call i32 (i32, i8*, ...) @dprintf(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %23
21: ; preds = %6
%22 = call i32 (i32, i8*, ...) @dprintf(i32 %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %12, %18, %21
%24 = phi i32 [ -1, %21 ], [ 0, %18 ], [ 0, %12 ]
%25 = call i32 @fclose(i32* %4)
br label %26
26: ; preds = %1, %23
%27 = phi i32 [ %24, %23 ], [ -1, %1 ]
ret i32 %27
}