#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 *, 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, "model name\t:", 12)) {
      dprintf(fd, "cpuinfo:desc=%s", &buf[13]);
      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    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    1227 <arch_fill_cpuinfo_model+0xd7>
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     1212 <arch_fill_cpuinfo_model+0xc2>
lea    -0x410(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    120d <arch_fill_cpuinfo_model+0xbd>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rdx
add    $0xd,%rdx
lea    0xe24(%rip),%rsi
call   1050 <dprintf@plt>
movl   $0x0,-0x41c(%rbp)
jmp    1212 <arch_fill_cpuinfo_model+0xc2>
jmp    11a1 <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    $0x408,%rsp
mov    %edi,%r14d
lea    0xe99(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <arch_fill_cpuinfo_model+0x81>
mov    %rax,%rbx
mov    %rsp,%rbp
lea    0xe8b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d8 <arch_fill_cpuinfo_model+0x88>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <arch_fill_cpuinfo_model+0x40>
lea    0xd(%rsp),%rdx
lea    0xe58(%rip),%rsi
mov    %r14d,%edi
call   1050 <dprintf@plt>
xor    %ebp,%ebp
jmp    11dd <arch_fill_cpuinfo_model+0x8d>
mov    $0xffffffff,%ebp
jmp    11e5 <arch_fill_cpuinfo_model+0x95>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x408,%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 = [13 x i8] c"model name\09:\00"
@.str.3 = [16 x i8] c"cpuinfo:desc=%s\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 %30
11: ; preds = %1
br label %12
12: ; preds = %25, %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 %26
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 ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%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 13
%24 = call i32 @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 %26
25: ; preds = %17
br label %12
26: ; preds = %21, %12
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %6
store i32 %29, i32* %2
br label %30
30: ; preds = %26, %10
%31 = load i32, i32* %2
ret i32 %31
}

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