#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
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, "CPU architecture:", 17)) {
      int v = 8;
      sscanf(&buf[18], "%d", &v);
      dprintf(fd, "cpuinfo:desc=ARM64 (v%d)\n", v);
      ret = 0;
      break;
    }
  }
  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    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11ac <arch_fill_cpuinfo_model+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <arch_fill_cpuinfo_model+0xfa>
jmp    11b1 <arch_fill_cpuinfo_model+0x51>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1245 <arch_fill_cpuinfo_model+0xe5>
lea    -0x410(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x11,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1240 <arch_fill_cpuinfo_model+0xe0>
movl   $0x8,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
add    $0x12,%rdi
lea    0xe12(%rip),%rsi
lea    -0x420(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x8(%rbp),%edi
mov    -0x420(%rbp),%edx
lea    0xdf9(%rip),%rsi
call   1050 <dprintf@plt>
movl   $0x0,-0x41c(%rbp)
jmp    1245 <arch_fill_cpuinfo_model+0xe5>
jmp    11b1 <arch_fill_cpuinfo_model+0x51>
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   %rbx
sub    $0x418,%rsp
mov    %edi,%r14d
lea    0xe89(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fe <arch_fill_cpuinfo_model+0x9e>
mov    %rax,%rbx
lea    0x10(%rsp),%rbp
lea    0xe79(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1205 <arch_fill_cpuinfo_model+0xa5>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x11,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11a0 <arch_fill_cpuinfo_model+0x40>
movl   $0x8,0xc(%rsp)
lea    0x22(%rsp),%rdi
lea    0xe45(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
mov    0xc(%rsp),%edx
lea    0xe33(%rip),%rsi
mov    %r14d,%edi
call   1050 <dprintf@plt>
xor    %ebp,%ebp
jmp    120a <arch_fill_cpuinfo_model+0xaa>
mov    $0xffffffff,%ebp
jmp    1212 <arch_fill_cpuinfo_model+0xb2>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
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 = [18 x i8] c"CPU architecture:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [26 x i8] c"cpuinfo:desc=ARM64 (v%d)\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
%7 = alloca i32
store i32 %0, i32* %3
store i32 -1, i32* %6
%8 = 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* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %33
12: ; preds = %1
br label %13
13: ; preds = %28, %12
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = call i32* @fgets(i8* %14, i32 1024, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%21 = icmp ne i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18
store i32 8, i32* %7
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 18
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%25 = load i32, i32* %3
%26 = load i32, i32* %7
%27 = call i32 @dprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %26)
store i32 0, i32* %6
br label %29
28: ; preds = %18
br label %13
29: ; preds = %22, %13
%30 = load i32*, i32** %5
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %6
store i32 %32, i32* %2
br label %33
33: ; preds = %29, %11
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"CPU architecture:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [26 x i8] c"cpuinfo:desc=ARM64 (v%d)\0A\00"
define i32 @arch_fill_cpuinfo_model(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%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 %22, label %7
7: ; preds = %1, %10
%8 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %10
%14 = bitcast i32* %3 to i8*
store i32 8, i32* %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 18
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = call i32 @dprintf(i32 %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %7, %13
%20 = phi i32 [ 0, %13 ], [ -1, %7 ]
%21 = call i32 @fclose(i32* %5)
br label %22
22: ; preds = %1, %19
%23 = phi i32 [ %20, %19 ], [ -1, %1 ]
ret i32 %23
}