#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*/ machine;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(int /*<<< orphan*/, char *, int);
scalar_t__ uname(struct utsname *);
int check_kernel_mode() {
  struct utsname uname_struct;
  if (uname(&uname_struct)) {
    fprintf(stderr, "Unable to get name and information about "
                    "current kernel. \n");
    perror("");
    return 1;
  }
  if (strncmp(uname_struct.machine, "s390x", 5) == 0) {
    fprintf(stderr, "=========================================="
                    "=======\n");
    fprintf(stderr, "WARNING: You are running an s390x (ESAME) "
                    "kernel.\n");
    fprintf(stderr, "         Your dump tool however is s390 "
                    "(ESA).\n");
    fprintf(stderr, "=========================================="
                    "=======\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_kernel_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1040 <uname@plt>
cmp    $0x0,%rax
je     1188 <check_kernel_mode+0x48>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xec3(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <check_kernel_mode+0xc1>
mov    -0x8(%rbp),%edi
lea    0xea9(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fa <check_kernel_mode+0xba>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xec7(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_kernel_mode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1040 <uname@plt>
test   %rax,%rax
jne    11c2 <check_kernel_mode+0x82>
mov    0x8(%rsp),%edi
lea    0xed8(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11b6 <check_kernel_mode+0x76>
mov    0x2e65(%rip),%r15
mov    (%r15),%edi
lea    0xebc(%rip),%r14
mov    %r14,%rsi
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xedd(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xf01(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe5c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    11b6 <check_kernel_mode+0x76>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"Unable to get name and information about current kernel. \0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"s390x\00"
@.str.3 = [51 x i8] c"=================================================\0A\00"
@.str.4 = [51 x i8] c"WARNING: You are running an s390x (ESAME) kernel.\0A\00"
@.str.5 = [48 x i8] c" Your dump tool however is s390 (ESA).\0A\00"
define i32 @check_kernel_mode() {
%1 = alloca i32
%2 = alloca %struct.utsname
%3 = call i64 @uname(%struct.utsname* %2)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %24
9: ; preds = %0
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @strncmp(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %14, %9
store i32 0, i32* %1
br label %24
24: ; preds = %23, %5
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"Unable to get name and information about current kernel. \0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"s390x\00"
@.str.3 = [51 x i8] c"=================================================\0A\00"
@.str.4 = [51 x i8] c"WARNING: You are running an s390x (ESAME) kernel.\0A\00"
@.str.5 = [48 x i8] c" Your dump tool however is s390 (ESA).\0A\00"
define i32 @check_kernel_mode() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = call i64 @uname(%struct.utsname* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %23
9: ; preds = %0
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @strncmp(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %9, %14, %5
%24 = phi i32 [ 1, %5 ], [ 0, %14 ], [ 0, %9 ]
ret i32 %24
}