#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 sscanf(int /*<<< orphan*/, char *, int *, int *, int *);
scalar_t__ uname(struct utsname *);
int get_kernel_version(void) {
  int version, subversion, patchlevel;
  struct utsname utsn;
  if (uname(&utsn))
    return 0;
  if (sscanf(utsn.release, "%d.%d.%d", &version, &subversion, &patchlevel) != 3)
    return 0;
  return (version << 16) + (subversion << 8) + patchlevel;
}


x86 assembly (clang, -O0):
<get_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
call   1030 <uname@plt>
cmp    $0x0,%rax
je     1147 <get_kernel_version+0x27>
movl   $0x0,-0x4(%rbp)
jmp    118b <get_kernel_version+0x6b>
mov    -0x18(%rbp),%edi
lea    0xeaf(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
je     1177 <get_kernel_version+0x57>
movl   $0x0,-0x4(%rbp)
jmp    118b <get_kernel_version+0x6b>
mov    -0x8(%rbp),%eax
shl    $0x10,%eax
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_kernel_version>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
call   1030 <uname@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    116b <get_kernel_version+0x4b>
mov    (%rsp),%edi
lea    0xec2(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    116b <get_kernel_version+0x4b>
mov    0xc(%rsp),%eax
shl    $0x10,%eax
mov    0x8(%rsp),%ebx
shl    $0x8,%ebx
add    %eax,%ebx
add    0x4(%rsp),%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 @get_kernel_version() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.utsname
%6 = call i64 @uname(%struct.utsname* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %23
9: ; preds = %0
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, 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* %2, i32* %3, i32* %4)
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* %1
br label %23
15: ; preds = %9
%16 = load i32, i32* %2
%17 = shl i32 %16, 16
%18 = load i32, i32* %3
%19 = shl i32 %18, 8
%20 = add nsw i32 %17, %19
%21 = load i32, i32* %4
%22 = add nsw i32 %20, %21
store i32 %22, i32* %1
br label %23
23: ; preds = %15, %14, %8
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @get_kernel_version() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.utsname
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.utsname* %4 to i8*
%9 = call i64 @uname(%struct.utsname* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %0
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, 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* %1, i32* %2, i32* %3)
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %1
%18 = shl i32 %17, 16
%19 = load i32, i32* %2
%20 = shl i32 %19, 8
%21 = add nsw i32 %20, %18
%22 = load i32, i32* %3
%23 = add nsw i32 %21, %22
br label %24
24: ; preds = %11, %0, %16
%25 = phi i32 [ %23, %16 ], [ 0, %0 ], [ 0, %11 ]
ret i32 %25
}