#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 KRELEASE(int, int, int);
int sscanf(int /*<<< orphan*/, char *, int *, int *, int *);
scalar_t__ uname(struct utsname *);
int kernel_version(void) {
  struct utsname uts;
  int major, minor, patch;
  if (uname(&uts) < 0)
    return -1;
  if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
    return -1;
  return KRELEASE(major, minor, patch);
}


x86 assembly (clang, -O0):
<kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1030 <uname@plt>
cmp    $0x0,%rax
jge    1157 <kernel_version+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <kernel_version+0x68>
mov    -0x8(%rbp),%edi
lea    0xe9f(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
je     1187 <kernel_version+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <kernel_version+0x68>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <KRELEASE@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_version>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
call   1030 <uname@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     117d <kernel_version+0x4d>
mov    (%rsp),%edi
lea    0xeaf(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    117d <kernel_version+0x4d>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
call   1050 <KRELEASE@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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