#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*/ output_string(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ readProcCpuInfo(char *, char *);
int /*<<< orphan*/ runCommand(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
void hardware(const int write_to_file, FILE *global_ofile) {
  char buffer[1024];
  char os[1024];
  char model[1024];
  char cache[1024];
  char os_command[] = "uname -s -r";
  runCommand(os_command, os);
  if (NULL != strstr(os, "Linux")) {
    readProcCpuInfo(model, cache);
  } else {
    model[0] = '\0';
    cache[0] = '\0';
  }
  sprintf(buffer, "CPU                 : %s\n", model);
  output_string(buffer, write_to_file, global_ofile);
  sprintf(buffer, "L2 Cache            : %s\n", cache);
  output_string(buffer, write_to_file, global_ofile);
  sprintf(buffer, "OS                  : %s\n", os);
  output_string(buffer, write_to_file, global_ofile);
}


x86 assembly (clang, -O0):
<hardware>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x101c(%rbp)
mov    0xe92(%rip),%eax
mov    %eax,-0x1014(%rbp)
lea    -0x101c(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1040 <runCommand@plt>
lea    -0x810(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c8 <hardware+0x78>
lea    -0xc10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1050 <readProcCpuInfo@plt>
jmp    11d6 <hardware+0x86>
movb   $0x0,-0xc10(%rbp)
movb   $0x0,-0x1010(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0xc10(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <output_string@plt>
lea    -0x410(%rbp),%rdi
lea    -0x1010(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <output_string@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <output_string@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hardware>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movabs $0x732d20656d616e75,%rax
20 2d 73
mov    %rax,(%rsp)
movl   $0x722d20,0x8(%rsp)
mov    %rsp,%rdi
lea    0x810(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <runCommand@plt>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11b1 <hardware+0x61>
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <readProcCpuInfo@plt>
jmp    11be <hardware+0x6e>
movb   $0x0,0x410(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe4d(%rip),%rsi
lea    0xc10(%rsp),%rbx
lea    0x410(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <output_string@plt>
lea    0xe3b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <output_string@plt>
lea    0xe34(%rip),%rsi
lea    0x810(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <output_string@plt>
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.hardware.os_command = [12 x i8] c"uname -s -r\00"
@.str = [6 x i8] c"Linux\00"
@.str.1 = [26 x i8] c"CPU : %s\0A\00"
@.str.2 = [26 x i8] c"L2 Cache : %s\0A\00"
@.str.3 = [26 x i8] c"OS : %s\0A\00"
define void @hardware(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [12 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = bitcast [12 x i8]* %9 to i8*
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 @runCommand(i8* %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = call i32* @strstr(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32* null, %15
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = call i32 @readProcCpuInfo(i8* %18, i8* %19)
br label %24
21: ; preds = %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8 0, i8* %22
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %23
br label %24
24: ; preds = %21, %17
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i32, i32* %3
%30 = load i32*, i32** %4
%31 = call i32 @output_string(i8* %28, i32 %29, i32* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%36 = load i32, i32* %3
%37 = load i32*, i32** %4
%38 = call i32 @output_string(i8* %35, i32 %36, i32* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = load i32, i32* %3
%44 = load i32*, i32** %4
%45 = call i32 @output_string(i8* %42, i32 %43, i32* %44)
ret void
}

LLVM IR (-O2):
@__const.hardware.os_command = [12 x i8] c"uname -s -r\00"
@.str = [6 x i8] c"Linux\00"
@.str.1 = [26 x i8] c"CPU : %s\0A\00"
@.str.2 = [26 x i8] c"L2 Cache : %s\0A\00"
@.str.3 = [26 x i8] c"OS : %s\0A\00"
define void @hardware(i32 %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [12 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%13 = call i32 @runCommand(i8* %12, i8* %9)
%14 = call i32* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = call i32 @readProcCpuInfo(i8* %10, i8* %11)
br label %19
18: ; preds = %2
store i8 0, i8* %10
store i8 0, i8* %11
br label %19
19: ; preds = %18, %16
%20 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%21 = call i32 @output_string(i8* %8, i32 %0, i32* %1)
%22 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%23 = call i32 @output_string(i8* %8, i32 %0, i32* %1)
%24 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%25 = call i32 @output_string(i8* %8, i32 %0, i32* %1)
ret void
}