#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 {
  int /*<<< orphan*/ release;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
int uname(struct utsname *);
void get_kernel_version(char *output, int max_length) {
  struct utsname u;
  int rv = uname(&u);
  if (rv != 0) {
    perror("[-] uname())");
    exit(EXIT_FAILURE);
  }
  assert(strlen(u.release) <= max_length);
  strcpy(&output[0], u.release);
}


x86 assembly (clang, -O0):
<get_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <uname@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119f <get_kernel_version+0x3f>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_kernel_version>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1050 <uname@plt>
test   %eax,%eax
jne    11a5 <get_kernel_version+0x45>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %ebp,%eax
setle  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strcpy@plt>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [13 x i8] c"[-] uname())\00"
@EXIT_FAILURE = global i32 0
define void @get_kernel_version(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.utsname
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 @uname(%struct.utsname* %5)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @strlen(i32 %16)
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strcpy(i8* %23, i32 %25)
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [13 x i8] c"[-] uname())\00"
@EXIT_FAILURE = global i32 0
define void @get_kernel_version(i8* %0, i32 %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i32 @uname(%struct.utsname* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @strlen(i32 %13)
%15 = icmp sle i32 %14, %1
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @strcpy(i8* %0, i32 %13)
ret void
}