#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 utsname {
  char *sysname;
  char *nodename;
  char *release;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ uname(struct utsname *);
void write_system_info_json(FILE *f) {
  struct utsname buf;
  uname(&buf);
  fprintf(f, "\t\"System Info\": {\n");
  fprintf(f, "\t\t\"OS\": \"%s\",\n", buf.sysname);
  fprintf(f, "\t\t\"Hostname\": \"%s\",\n", buf.nodename);
  fprintf(f, "\t\t\"Release\": \"%s\",\n", buf.release);
  fprintf(f, "\t\t\"CPU\": {");
  FILE *cmd = popen("lscpu 2> /dev/null", "r");
  if (cmd != NULL) {
    char id[256], val[1024];
    char *del = "\n";
    while (fscanf(cmd, "%[^:]%*c %[^\n]\n", id, val) == 2) {
      fprintf(f, "%s\t\t\t\"%s\": \"%s\"", del, id, val);
      del = ",\n";
    }
    fclose(cmd);
    fprintf(f, "\n");
  }
  fprintf(f, "\t\t}\n");
  fprintf(f, "\t},\n");
}


x86 assembly (clang, -O0):
<write_system_info_json>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <uname@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xe81(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     127a <write_system_info_json+0x12a>
lea    0xe29(%rip),%rax
mov    %rax,-0x538(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    -0x530(%rbp),%rcx
lea    0xe54(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    125f <write_system_info_json+0x10f>
mov    -0x8(%rbp),%rdi
mov    -0x538(%rbp),%rdx
lea    -0x130(%rbp),%rcx
lea    -0x530(%rbp),%r8
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xdcc(%rip),%rax
mov    %rax,-0x538(%rbp)
jmp    11fe <write_system_info_json+0xae>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_system_info_json>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x528,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1040 <uname@plt>
lea    0xe6b(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    0x8(%rsp),%rdx
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdx
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x18(%rsp),%rdx
lea    0xe58(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe5b(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
lea    0xe4d(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     12f5 <write_system_info_json+0x185>
mov    %rax,%r13
lea    0xe43(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x120(%rsp),%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    12e0 <write_system_info_json+0x170>
lea    0xe2e(%rip),%rsi
lea    0xdcc(%rip),%rdx
lea    0x20(%rsp),%rbx
lea    0x120(%rsp),%rbp
mov    %r14,%rdi
mov    %rbx,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdf3(%rip),%rsi
mov    %r13,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    12e0 <write_system_info_json+0x170>
lea    0xd8d(%rip),%r12
lea    0x20(%rsp),%rbx
lea    0x120(%rsp),%rbp
lea    0xdc5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xdc1(%rip),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1050 <fscanf@plt>
cmp    $0x2,%eax
je     12b0 <write_system_info_json+0x140>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
lea    0xd8f(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
lea    0xd7b(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8* }
@.str = [19 x i8] c"\09\22System Info\22: {\0A\00"
@.str.1 = [15 x i8] c"\09\09\22OS\22: \22%s\22,\0A\00"
@.str.2 = [21 x i8] c"\09\09\22Hostname\22: \22%s\22,\0A\00"
@.str.3 = [20 x i8] c"\09\09\22Release\22: \22%s\22,\0A\00"
@.str.4 = [11 x i8] c"\09\09\22CPU\22: {\00"
@.str.5 = [19 x i8] c"lscpu 2> /dev/null\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [16 x i8] c"%[^:]%*c %[^\0A]\0A\00"
@.str.9 = [16 x i8] c"%s\09\09\09\22%s\22: \22%s\22\00"
@.str.10 = [3 x i8] c",\0A\00"
@.str.11 = [5 x i8] c"\09\09}\0A\00"
@.str.12 = [5 x i8] c"\09},\0A\00"
define void @write_system_info_json(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.utsname
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i8*
store i32* %0, i32** %2
%8 = call i32 @uname(%struct.utsname* %3)
%9 = load i32*, i32** %2
%10 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %2
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i32 0, i32 1
%17 = load i8*, i8** %16
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %2
%20 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i32 0, i32 2
%21 = load i8*, i8** %20
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %2
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %25, i32** %4
%26 = load i32*, i32** %4
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %46
28: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %29
29: ; preds = %35, %28
%30 = load i32*, i32** %4
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %31, i8* %32)
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32*, i32** %2
%37 = load i8*, i8** %7
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %37, i8* %38, i8* %39)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8** %7
br label %29
41: ; preds = %29
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %2
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %41, %1
%47 = load i32*, i32** %2
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%49 = load i32*, i32** %2
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8* }
@.str = [19 x i8] c"\09\22System Info\22: {\0A\00"
@.str.1 = [15 x i8] c"\09\09\22OS\22: \22%s\22,\0A\00"
@.str.2 = [21 x i8] c"\09\09\22Hostname\22: \22%s\22,\0A\00"
@.str.3 = [20 x i8] c"\09\09\22Release\22: \22%s\22,\0A\00"
@.str.4 = [11 x i8] c"\09\09\22CPU\22: {\00"
@.str.5 = [19 x i8] c"lscpu 2> /dev/null\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [16 x i8] c"%[^:]%*c %[^\0A]\0A\00"
@.str.9 = [16 x i8] c"%s\09\09\09\22%s\22: \22%s\22\00"
@.str.10 = [3 x i8] c",\0A\00"
@.str.11 = [5 x i8] c"\09\09}\0A\00"
@.str.12 = [5 x i8] c"\09},\0A\00"
define void @write_system_info_json(i32* nocapture %0) {
%2 = alloca %struct.utsname
%3 = alloca [256 x i8]
%4 = alloca [1024 x i8]
%5 = bitcast %struct.utsname* %2 to i8*
%6 = call i32 @uname(%struct.utsname* %2)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 18, i64 1, i32* %0)
%8 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 2
%15 = load i8*, i8** %14
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 10, i64 1, i32* %0)
%18 = tail call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %36, label %20
20: ; preds = %1
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %21, i8* %22)
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* %21, i8* %22)
%27 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %21, i8* %22)
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %33
29: ; preds = %25, %29
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %21, i8* %22)
%31 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %21, i8* %22)
%32 = icmp eq i32 %31, 2
br i1 %32, label %29, label %33
33: ; preds = %29, %25, %20
%34 = call i32 @fclose(i32* %18)
%35 = call i32 @fputc(i32 10, i32* %0)
br label %36
36: ; preds = %33, %1
%37 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64 4, i64 1, i32* %0)
%38 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i64 4, i64 1, i32* %0)
ret void
}