#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;
};
typedef int /*<<< orphan*/ os_name;

/* Variables and functions */
scalar_t__ hefesto_mloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char tolower(char);
int uname(struct utsname *);
char *get_os_name() {
  char *result = NULL;
  static char os_name[255] = "";
  static size_t os_name_sz = 0;
  struct utsname unbuf;
  static size_t o;
  if (os_name_sz == 0 && uname(&unbuf) != -1) {
    strncpy(os_name, unbuf.sysname, sizeof(os_name) - 1);
    for (o = 0; os_name[o] != 0; o++) {
      os_name[o] = tolower(os_name[o]);
    }
  }
  if (os_name_sz == 0) {
    os_name_sz = strlen(os_name);
  }
  result = (char *)hefesto_mloc(os_name_sz + 1);
  memset(result, 0, os_name_sz + 1);
  strncpy(result, os_name, os_name_sz);
  return result;
}


x86 assembly (clang, -O0):
<get_os_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
cmpq   $0x0,0x2fe8(%rip)
jne    1211 <get_os_name+0xb1>
lea    -0x10(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     1211 <get_os_name+0xb1>
mov    -0x10(%rbp),%rsi
lea    0x2ec5(%rip),%rdi
mov    $0xfe,%edx
call   1030 <strncpy@plt>
movq   $0x0,0x2fb8(%rip)
mov    0x2fb1(%rip),%rcx
lea    0x2ea2(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     120c <get_os_name+0xac>
mov    0x2f96(%rip),%rcx
lea    0x2e87(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1080 <tolower@plt>
mov    %al,%dl
mov    0x2f7d(%rip),%rcx
lea    0x2e6e(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    0x2f6c(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2f61(%rip)
jmp    11b0 <get_os_name+0x50>
jmp    1211 <get_os_name+0xb1>
cmpq   $0x0,0x2f47(%rip)
jne    1232 <get_os_name+0xd2>
lea    0x2e3a(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,0x2f2e(%rip)
mov    0x2f27(%rip),%rdi
add    $0x1,%rdi
call   1070 <hefesto_mloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2f0f(%rip),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    0x2ef9(%rip),%rdx
lea    0x2df2(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_os_name>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ff4(%rip),%rdi
test   %rdi,%rdi
jne    1208 <get_os_name+0xa8>
lea    0x8(%rsp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     11e6 <get_os_name+0x86>
mov    0x8(%rsp),%rsi
lea    0x2ed0(%rip),%rbx
mov    $0xfe,%edx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
movq   $0x0,0x2fc0(%rip)
mov    0x2eb2(%rip),%al
test   %al,%al
je     11e6 <get_os_name+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1080 <tolower@plt>
mov    0x2f99(%rip),%rcx
mov    %al,(%rcx,%rbx,1)
lea    0x1(%rcx),%rax
mov    %rax,0x2f8b(%rip)
movzbl 0x1(%rcx,%rbx,1),%eax
test   %al,%al
jne    11c0 <get_os_name+0x60>
mov    0x2f73(%rip),%rdi
test   %rdi,%rdi
jne    1208 <get_os_name+0xa8>
lea    0x2e67(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
mov    %rax,0x2f58(%rip)
add    $0x1,%rdi
call   1070 <hefesto_mloc@plt>
mov    %rax,%rbx
mov    0x2f45(%rip),%rdx
add    $0x1,%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2f30(%rip),%rdx
lea    0x2e29(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
@get_os_name.os_name = internal global [255 x i8] zeroinitializer
@get_os_name.os_name_sz = internal global i64 0
@get_os_name.o = internal global i64 0
define i8* @get_os_name() {
%1 = alloca i8*
%2 = alloca %struct.utsname
store i8* null, i8** %1
%3 = load i64, i64* @get_os_name.os_name_sz
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %29
5: ; preds = %0
%6 = call i32 @uname(%struct.utsname* %2)
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i32 @strncpy(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0), i8* %10, i64 254)
store i64 0, i64* @get_os_name.o
br label %12
12: ; preds = %25, %8
%13 = load i64, i64* @get_os_name.o
%14 = getelementptr inbounds [255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i64, i64* @get_os_name.o
%20 = getelementptr inbounds [255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
%23 = load i64, i64* @get_os_name.o
%24 = getelementptr inbounds [255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 %23
store i8 %22, i8* %24
br label %25
25: ; preds = %18
%26 = load i64, i64* @get_os_name.o
%27 = add i64 %26, 1
store i64 %27, i64* @get_os_name.o
br label %12
28: ; preds = %12
br label %29
29: ; preds = %28, %5, %0
%30 = load i64, i64* @get_os_name.os_name_sz
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i64 @strlen(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0))
store i64 %33, i64* @get_os_name.os_name_sz
br label %34
34: ; preds = %32, %29
%35 = load i64, i64* @get_os_name.os_name_sz
%36 = add i64 %35, 1
%37 = call i64 @hefesto_mloc(i64 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %1
%39 = load i8*, i8** %1
%40 = load i64, i64* @get_os_name.os_name_sz
%41 = add i64 %40, 1
%42 = call i32 @memset(i8* %39, i32 0, i64 %41)
%43 = load i8*, i8** %1
%44 = load i64, i64* @get_os_name.os_name_sz
%45 = call i32 @strncpy(i8* %43, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0), i64 %44)
%46 = load i8*, i8** %1
ret i8* %46
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@get_os_name.os_name = internal global [255 x i8] zeroinitializer
@get_os_name.os_name_sz = internal unnamed_addr global i64 0
@get_os_name.o = internal unnamed_addr global i64 0
define i8* @get_os_name() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = load i64, i64* @get_os_name.os_name_sz
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %28
5: ; preds = %0
%6 = call i32 @uname(%struct.utsname* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = tail call i32 @strncpy(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0), i8* %10, i64 254)
store i64 0, i64* @get_os_name.o
%12 = load i8, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0)
%13 = icmp eq i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %8, %14
%15 = phi i8 [ %21, %14 ], [ %12, %8 ]
%16 = tail call signext i8 @tolower(i8 signext %15)
%17 = load i64, i64* @get_os_name.o
%18 = getelementptr inbounds [255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 %17
store i8 %16, i8* %18
%19 = add i64 %17, 1
store i64 %19, i64* @get_os_name.o
%20 = getelementptr inbounds [255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %8, %5
%24 = load i64, i64* @get_os_name.os_name_sz
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0))
store i64 %27, i64* @get_os_name.os_name_sz
br label %28
28: ; preds = %0, %26, %23
%29 = phi i64 [ %3, %0 ], [ %27, %26 ], [ %24, %23 ]
%30 = add i64 %29, 1
%31 = tail call i64 @hefesto_mloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
%33 = load i64, i64* @get_os_name.os_name_sz
%34 = add i64 %33, 1
%35 = tail call i32 @memset(i8* %32, i32 0, i64 %34)
%36 = load i64, i64* @get_os_name.os_name_sz
%37 = tail call i32 @strncpy(i8* %32, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_os_name.os_name, i64 0, i64 0), i64 %36)
ret i8* %32
}