#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 uint32_t;
typedef int /*<<< orphan*/ line1;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int sprintf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ sysctlbyname(char *, char *, size_t *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/);
void get_system_infos(char *buffer, uint32_t *pos, uint32_t max) {
  char line1[0x1000];
  char line2[0x1000];
  char line3[0x1000];
  FILE *fp = NULL;
  size_t size = sizeof(line1);
  fp = popen("sw_vers -productVersion", "r");
  fgets(line3, 16, fp);
  pclose(fp);
  sysctlbyname("kern.osrelease", line1, &size, NULL, 0);
  sysctlbyname("kern.osversion", line2, &size, NULL, 0);
  (*pos) += sprintf(
      buffer + (*pos),
      "XNU System Infos:%s\nproductVersion\t\t%ssysctl "
      "kern.osrelease\t%s\nsysctl kern.osversion\t%s\n\n",
      "\n------------------------------------------------------------------",
      line3, line1, line2);
}


x86 assembly (clang, -O0):
<get_system_infos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x3028(%rbp)
movq   $0x1000,-0x3030(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x3028(%rbp)
lea    -0x3020(%rbp),%rdi
mov    -0x3028(%rbp),%rdx
mov    $0x10,%esi
call   1040 <fgets@plt>
mov    -0x3028(%rbp),%rdi
call   1030 <pclose@plt>
lea    -0x1020(%rbp),%rsi
lea    0xe52(%rip),%rdi
lea    -0x3030(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1070 <sysctlbyname@plt>
lea    -0x2020(%rbp),%rsi
lea    0xe40(%rip),%rdi
lea    -0x3030(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1070 <sysctlbyname@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    -0x3020(%rbp),%rcx
lea    -0x1020(%rbp),%r8
lea    -0x2020(%rbp),%r9
lea    0xe12(%rip),%rsi
lea    0xe65(%rip),%rdx
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x3030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_system_infos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3018,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
movq   $0x1000,0x8(%rsp)
lea    0xe89(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <pclose@plt>
lea    0xe70(%rip),%rdi
lea    0x2010(%rsp),%r13
lea    0x8(%rsp),%rbx
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <sysctlbyname@plt>
lea    0xe5b(%rip),%rdi
lea    0x1010(%rsp),%rbp
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <sysctlbyname@plt>
movslq (%r12),%rdi
add    %r14,%rdi
lea    0xe44(%rip),%rsi
lea    0xe97(%rip),%rdx
mov    %r15,%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1060 <sprintf@plt>
add    %eax,(%r12)
add    $0x3018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"sw_vers -productVersion\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"kern.osrelease\00"
@.str.3 = [15 x i8] c"kern.osversion\00"
@.str.4 = [90 x i8] c"XNU System Infos:%s\0AproductVersion\09\09%ssysctl kern.osrelease\09%s\0Asysctl kern.osversion\09%s\0A\0A\00"
@.str.5 = [68 x i8] c"\0A------------------------------------------------------------------\00"
define void @get_system_infos(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca [4096 x i8]
%9 = alloca [4096 x i8]
%10 = alloca i32*
%11 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32* null, i32** %10
store i64 4096, i64* %11
%12 = call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %10
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%14 = load i32*, i32** %10
%15 = call i32 @fgets(i8* %13, i32 16, i32* %14)
%16 = load i32*, i32** %10
%17 = call i32 @pclose(i32* %16)
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%19 = call i32 @sysctlbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18, i64* %11, i32* null, i32 0)
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%21 = call i32 @sysctlbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %20, i64* %11, i32* null, i32 0)
%22 = load i8*, i8** %4
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%30 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i8* %27, i8* %28, i8* %29)
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %30
store i32 %33, i32* %31
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"sw_vers -productVersion\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"kern.osrelease\00"
@.str.3 = [15 x i8] c"kern.osversion\00"
@.str.4 = [90 x i8] c"XNU System Infos:%s\0AproductVersion\09\09%ssysctl kern.osrelease\09%s\0Asysctl kern.osversion\09%s\0A\0A\00"
@.str.5 = [68 x i8] c"\0A------------------------------------------------------------------\00"
define void @get_system_infos(i8* nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i64
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%11 = bitcast i64* %7 to i8*
store i64 4096, i64* %7
%12 = tail call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @fgets(i8* %10, i32 16, i32* %12)
%14 = call i32 @pclose(i32* %12)
%15 = call i32 @sysctlbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %8, i64* %7, i32* null, i32 0)
%16 = call i32 @sysctlbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %9, i64* %7, i32* null, i32 0)
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* %8, i8* %9)
%21 = load i32, i32* %1
%22 = add nsw i32 %21, %20
store i32 %22, i32* %1
ret void
}