#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;
  char *nodename;
  char *release;
  char *version;
  char *machine;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int uname(struct utsname *);
int main(int argc, char const *argv[]) {
  struct utsname un;
  char hostname[256];
  if (uname(&un) == -1) {
    perror("uname failed: ");
    exit(1);
  }
  printf("System name: %s\n", un.sysname);
  printf("Network name: %s\n", un.nodename);
  printf("Release level: %s\n", un.release);
  printf("OS version: %s\n", un.version);
  printf("Hardware platform: %s\n", un.machine);
  if (gethostname(hostname, 256) == 0) {
    printf("Hostname: %s\n", hostname);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
call   1040 <uname@plt>
cmp    $0xffffffff,%eax
jne    1191 <main+0x41>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jne    120f <main+0xbf>
lea    -0x140(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x138,%rsp
lea    0x8(%rsp),%rdi
call   1040 <uname@plt>
cmp    $0xffffffff,%eax
je     11ee <main+0x9e>
mov    0x8(%rsp),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    0x20(%rsp),%rsi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    0x28(%rsp),%rsi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
jne    11e4 <main+0x94>
lea    0xe92(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x138,%rsp
ret
lea    0xe0b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8*, i8*, i8* }
@.str = [15 x i8] c"uname failed: \00"
@.str.1 = [17 x i8] c"System name: %s\0A\00"
@.str.2 = [18 x i8] c"Network name: %s\0A\00"
@.str.3 = [19 x i8] c"Release level: %s\0A\00"
@.str.4 = [16 x i8] c"OS version: %s\0A\00"
@.str.5 = [23 x i8] c"Hardware platform: %s\0A\00"
@.str.6 = [14 x i8] c"Hostname: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.utsname
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @uname(%struct.utsname* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 1
%18 = load i8*, i8** %17
%19 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 2
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 3
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 4
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = call i64 @gethostname(i8* %29, i32 256)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %13
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %13
ret i32 0
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8*, i8*, i8* }
@.str = [15 x i8] c"uname failed: \00"
@.str.1 = [17 x i8] c"System name: %s\0A\00"
@.str.2 = [18 x i8] c"Network name: %s\0A\00"
@.str.3 = [19 x i8] c"Release level: %s\0A\00"
@.str.4 = [16 x i8] c"OS version: %s\0A\00"
@.str.5 = [23 x i8] c"Hardware platform: %s\0A\00"
@.str.6 = [14 x i8] c"Hostname: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.utsname
%4 = alloca [256 x i8]
%5 = bitcast %struct.utsname* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @uname(%struct.utsname* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 1
%17 = load i8*, i8** %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 2
%20 = load i8*, i8** %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 3
%23 = load i8*, i8** %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 4
%26 = load i8*, i8** %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = call i64 @gethostname(i8* %6, i32 256)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %12
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %6)
br label %32
32: ; preds = %30, %12
ret i32 0
}