#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 */
struct cpu_map {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct cpu_map *cpu_map__def_new();
struct cpu_map *cpu_map__read(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct cpu_map *cpu_map__read_all(void) {
  struct cpu_map *cpus = NULL;
  FILE *fp;
  fp = fopen("/sys/devices/system/cpu/online", "r");
  if (!fp)
    return cpu_map__def_new();
  cpus = cpu_map__read(fp);
  fclose(fp);
  return cpus;
}


x86 assembly (clang, -O0):
<cpu_map__read_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xea9(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <cpu_map__read_all+0x42>
mov    $0x0,%al
call   1060 <cpu_map__def_new@plt>
mov    %rax,-0x8(%rbp)
jmp    11a0 <cpu_map__read_all+0x60>
mov    -0x18(%rbp),%rdi
call   1030 <cpu_map__read@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_map__read_all>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117d <cpu_map__read_all+0x3d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <cpu_map__read@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <cpu_map__def_new@plt>

LLVM IR (-O0):
%struct.cpu_map = type { i32 }
@.str = [31 x i8] c"/sys/devices/system/cpu/online\00"
@.str.1 = [2 x i8] c"r\00"
define %struct.cpu_map* @cpu_map__read_all() {
%1 = alloca %struct.cpu_map*
%2 = alloca %struct.cpu_map*
%3 = alloca i32*
store %struct.cpu_map* null, %struct.cpu_map** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call %struct.cpu_map* (...) @cpu_map__def_new()
store %struct.cpu_map* %8, %struct.cpu_map** %1
br label %15
9: ; preds = %0
%10 = load i32*, i32** %3
%11 = call %struct.cpu_map* @cpu_map__read(i32* %10)
store %struct.cpu_map* %11, %struct.cpu_map** %2
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
%14 = load %struct.cpu_map*, %struct.cpu_map** %2
store %struct.cpu_map* %14, %struct.cpu_map** %1
br label %15
15: ; preds = %9, %7
%16 = load %struct.cpu_map*, %struct.cpu_map** %1
ret %struct.cpu_map* %16
}

LLVM IR (-O2):
%struct.cpu_map = type { i32 }
@.str = [31 x i8] c"/sys/devices/system/cpu/online\00"
@.str.1 = [2 x i8] c"r\00"
define %struct.cpu_map* @cpu_map__read_all() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call %struct.cpu_map* (...) @cpu_map__def_new()
br label %8
5: ; preds = %0
%6 = tail call %struct.cpu_map* @cpu_map__read(i32* %1)
%7 = tail call i32 @fclose(i32* %1)
br label %8
8: ; preds = %5, %3
%9 = phi %struct.cpu_map* [ %6, %5 ], [ %4, %3 ]
ret %struct.cpu_map* %9
}