#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*/ EBADMSG;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ mced_debug(int, char *, unsigned int, unsigned int,
                              unsigned int);
int sscanf(int /*<<< orphan*/, char *, unsigned int *, unsigned int *,
           unsigned int *);
int uname(struct utsname *);
int get_kernel_version(unsigned *vmajor, unsigned *vminor, unsigned *vmicro) {
  struct utsname u;
  int r = uname(&u);
  if (r < 0) {
    return r;
  }
  r = sscanf(u.release, "%u.%u.%u", vmajor, vminor, vmicro);
  if (r != 3) {
    errno = EBADMSG;
    return -1;
  }
  mced_debug(1, "DBG: found kernel %u.%u.%u\n", *vmajor, *vminor, *vmicro);
  return 0;
}


x86 assembly (clang, -O0):
<get_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <uname@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1165 <get_kernel_version+0x35>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <get_kernel_version+0xa6>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe85(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
je     11ab <get_kernel_version+0x7b>
mov    0x2e54(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <get_kernel_version+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8d
mov    $0x1,%edi
lea    0xe3f(%rip),%rsi
call   1050 <mced_debug@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_kernel_version>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <uname@plt>
test   %eax,%eax
js     11a2 <get_kernel_version+0x72>
mov    0x8(%rsp),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    118b <get_kernel_version+0x5b>
mov    (%rbx),%edx
mov    (%r15),%ecx
mov    (%r14),%r8d
lea    0xe8c(%rip),%rsi
mov    $0x1,%edi
call   1050 <mced_debug@plt>
xor    %eax,%eax
jmp    11a2 <get_kernel_version+0x72>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    0x2e3d(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [9 x i8] c"%u.%u.%u\00"
@EBADMSG = global i32 0
@errno = global i32 0
@.str.1 = [28 x i8] c"DBG: found kernel %u.%u.%u\0A\00"
define i32 @get_kernel_version(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.utsname
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = call i32 @uname(%struct.utsname* %8)
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %9
store i32 %14, i32* %4
br label %34
15: ; preds = %3
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32*, i32** %5
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = call i32 @sscanf(i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %18, i32* %19, i32* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i32, i32* @EBADMSG
store i32 %25, i32* @errno
store i32 -1, i32* %4
br label %34
26: ; preds = %15
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = call i32 @mced_debug(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %30, i32 %32)
store i32 0, i32* %4
br label %34
34: ; preds = %26, %24, %13
%35 = load i32, i32* %4
ret i32 %35
}

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