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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ uname(struct utsname *);
char const *get_kernel_version(void) {
  static char ret[255];
  struct utsname sys;
  uname(&sys);
  if ((strlen(sys.sysname) + strlen(sys.version)) > 255)
    return NULL;
  snprintf(ret, 255, "%s %s", sys.sysname, sys.release);
  return ret;
}


x86 assembly (clang, -O0):
<get_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
call   1050 <uname@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
cmp    $0xff,%eax
jle    1175 <get_kernel_version+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <get_kernel_version+0x70>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ecc(%rip),%rdi
mov    $0xff,%esi
lea    0xe70(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2eb4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_kernel_version>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rdi
call   1050 <uname@plt>
mov    (%rsp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
cmp    $0xff,%eax
jle    1164 <get_kernel_version+0x34>
xor    %ebx,%ebx
jmp    1187 <get_kernel_version+0x57>
mov    0x10(%rsp),%r8
lea    0x2ee0(%rip),%rbx
lea    0xe89(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8* }
@get_kernel_version.ret = internal global [255 x i8] zeroinitializer
@.str = [6 x i8] c"%s %s\00"
define i8* @get_kernel_version() {
%1 = alloca i8*
%2 = alloca %struct.utsname
%3 = call i32 @uname(%struct.utsname* %2)
%4 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%5 = load i8*, i8** %4
%6 = call i32 @strlen(i8* %5)
%7 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 1
%8 = load i8*, i8** %7
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %6, %9
%11 = icmp sgt i32 %10, 255
br i1 %11, label %12, label %13
12: ; preds = %0
store i8* null, i8** %1
br label %19
13: ; preds = %0
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 2
%17 = load i8*, i8** %16
%18 = call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_kernel_version.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17)
store i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_kernel_version.ret, i64 0, i64 0), i8** %1
br label %19
19: ; preds = %13, %12
%20 = load i8*, i8** %1
ret i8* %20
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8* }
@get_kernel_version.ret = internal global [255 x i8] zeroinitializer
@.str = [6 x i8] c"%s %s\00"
define i8* @get_kernel_version() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = call i32 @uname(%struct.utsname* %1)
%4 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* %5)
%7 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, %6
%11 = icmp sgt i32 %10, 255
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 2
%14 = load i8*, i8** %13
%15 = tail call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_kernel_version.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %14)
br label %16
16: ; preds = %0, %12
%17 = phi i8* [ getelementptr inbounds ([255 x i8], [255 x i8]* @get_kernel_version.ret, i64 0, i64 0), %12 ], [ null, %0 ]
ret i8* %17
}