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

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int swprintf(int /*<<< orphan*/ *, int, char *, char *, char *);
scalar_t__ uname(struct utsname *);
wchar_t *getOS() {
  struct utsname system_info;
  if (uname(&system_info) != 0)
    return NULL;
  wchar_t *os = malloc(sizeof(os) * 128);
  if (swprintf(os, 128, L"%s %s", system_info.sysname, system_info.release) ==
      -1) {
    free(os);
    os = NULL;
  }
  return os;
}


x86 assembly (clang, -O0):
<getOS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
call   1040 <uname@plt>
cmp    $0x0,%rax
je     1168 <getOS+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <getOS+0x75>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x80,%esi
lea    0xe72(%rip),%rdx
call   1050 <swprintf@plt>
cmp    $0xffffffff,%eax
jne    11ad <getOS+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getOS>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
call   1040 <uname@plt>
test   %rax,%rax
je     1156 <getOS+0x16>
xor    %ebx,%ebx
jmp    1185 <getOS+0x45>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%rsp),%rcx
mov    0x8(%rsp),%r8
lea    0xe8d(%rip),%rdx
mov    %rax,%rdi
mov    $0x80,%esi
call   1050 <swprintf@plt>
cmp    $0xffffffff,%eax
je     118e <getOS+0x4e>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1152 <getOS+0x12>

LLVM IR (-O0):
%struct.utsname = type { i8*, i8* }
@.str = [6 x i32] [i32 37, i32 115, i32 32, i32 37, i32 115, i32 0]
define i32* @getOS() {
%1 = alloca i32*
%2 = alloca %struct.utsname
%3 = alloca i32*
%4 = call i64 @uname(%struct.utsname* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32* null, i32** %1
br label %21
7: ; preds = %0
%8 = call i32* @malloc(i32 1024)
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 1
%13 = load i8*, i8** %12
%14 = call i32 @swprintf(i32* %9, i32 128, i8* bitcast ([6 x i32]* @.str to i8*), i8* %11, i8* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = load i32*, i32** %3
%18 = call i32 @free(i32* %17)
store i32* null, i32** %3
br label %19
19: ; preds = %16, %7
%20 = load i32*, i32** %3
store i32* %20, i32** %1
br label %21
21: ; preds = %19, %6
%22 = load i32*, i32** %1
ret i32* %22
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8* }
@.str = [6 x i32] [i32 37, i32 115, i32 32, i32 37, i32 115, i32 0]
define i32* @getOS() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = call i64 @uname(%struct.utsname* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = tail call i32* @malloc(i32 1024)
%7 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 1
%10 = load i8*, i8** %9
%11 = tail call i32 @swprintf(i32* %6, i32 128, i8* bitcast ([6 x i32]* @.str to i8*), i8* %8, i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 @free(i32* %6)
br label %15
15: ; preds = %5, %13, %0
%16 = phi i32* [ null, %0 ], [ null, %13 ], [ %6, %5 ]
ret i32* %16
}