#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 *version;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int uname(struct utsname *);
void get_os(char *buffer, size_t size) {
  struct utsname name;
  if (uname(&name) != -1)
    snprintf(buffer, size, "Solaris %s", name.version);
  else
    strncpy(buffer, "unknown Solaris", size);
}


x86 assembly (clang, -O0):
<get_os>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     116f <get_os+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe9b(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1183 <get_os+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_os>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1050 <uname@plt>
cmp    $0xffffffff,%eax
je     1164 <get_os+0x34>
mov    (%rsp),%rcx
lea    0xeae(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <snprintf@plt>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
%struct.utsname = type { i8* }
@.str = [11 x i8] c"Solaris %s\00"
@.str.1 = [16 x i8] c"unknown Solaris\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.utsname
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = call i32 @uname(%struct.utsname* %5)
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @snprintf(i8* %9, i64 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %18
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %14, %8
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@.str = [11 x i8] c"Solaris %s\00"
@.str.1 = [16 x i8] c"unknown Solaris\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i32 @uname(%struct.utsname* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %13
11: ; preds = %2
%12 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %13
13: ; preds = %11, %7
ret void
}