#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*/ uname_str;
struct utsname {
  char *nodename;
  char *sysname;
  char *release;
  char *version;
  char *machine;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *, char *,
                            char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ uname(struct utsname *);
char *misc_getunamestr(char *uname_str, int len) {
  struct utsname uts;
  if (uname(&uts) < 0)
    strncpy(uname_str, "Undefined host", sizeof(uname_str) - 1);
  else
    snprintf(uname_str, len - 1, "%s [%s %s %s %s]", uts.nodename, uts.sysname,
             uts.release, uts.version, uts.machine);
  return uname_str;
}


x86 assembly (clang, -O0):
<misc_getunamestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x38(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0x0,%rax
jge    116c <misc_getunamestr+0x3c>
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
jmp    119f <misc_getunamestr+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x20(%rbp),%r10
mov    -0x18(%rbp),%rax
lea    0xe7e(%rip),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<misc_getunamestr>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
call   1050 <uname@plt>
test   %rax,%rax
js     1178 <misc_getunamestr+0x48>
add    $0xffffffff,%ebp
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
movups 0x28(%rsp),%xmm0
movups %xmm0,(%rsp)
lea    0xea3(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <snprintf@plt>
jmp    118c <misc_getunamestr+0x5c>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8*, i8*, i8* }
@.str = [15 x i8] c"Undefined host\00"
@.str.1 = [17 x i8] c"%s [%s %s %s %s]\00"
define i8* @misc_getunamestr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.utsname
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i64 @uname(%struct.utsname* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 7)
br label %26
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 2
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 3
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 4
%24 = load i8*, i8** %23
%25 = call i32 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18, i8* %20, i8* %22, i8* %24)
br label %26
26: ; preds = %11, %8
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8*, i8*, i8* }
@.str = [15 x i8] c"Undefined host\00"
@.str.1 = [17 x i8] c"%s [%s %s %s %s]\00"
define i8* @misc_getunamestr(i8* returned %0, i32 %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i64 @uname(%struct.utsname* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 7)
br label %22
9: ; preds = %2
%10 = add nsw i32 %1, -1
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 3
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 4
%20 = load i8*, i8** %19
%21 = tail call i32 @snprintf(i8* %0, i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14, i8* %16, i8* %18, i8* %20)
br label %22
22: ; preds = %9, %7
ret i8* %0
}