#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;
};
typedef int /*<<< orphan*/ errStr;

/* Variables and functions */
int /*<<< orphan*/ dbgprintf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ rs_strerror_r(int /*<<< orphan*/, char *, int);
int sscanf(int /*<<< orphan*/, char *, unsigned int *, unsigned int *);
scalar_t__ uname(struct utsname *);
int should_use_so_bsdcompat(void) {
  static int init_done;
  static int so_bsdcompat_is_obsolete;
  if (!init_done) {
    struct utsname myutsname;
    unsigned int version, patchlevel;
    init_done = 1;
    if (uname(&myutsname) < 0) {
      char errStr[1024];
      dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr)));
      return 1;
    }
    if (sscanf(myutsname.release, "%u.%u", &version, &patchlevel) != 2) {
      dbgprintf("uname: unexpected release '%s'\r\n", myutsname.release);
      return 1;
    }
    if (version > 2 || (version == 2 && patchlevel >= 5))
      so_bsdcompat_is_obsolete = 1;
  }
  return !so_bsdcompat_is_obsolete;
}


x86 assembly (clang, -O0):
<should_use_so_bsdcompat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
cmpl   $0x0,0x2ef2(%rip)
jne    1211 <should_use_so_bsdcompat+0xd1>
movl   $0x1,0x2ee2(%rip)
lea    -0x8(%rbp),%rdi
call   1030 <uname@plt>
cmp    $0x0,%rax
jge    11a9 <should_use_so_bsdcompat+0x69>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <rs_strerror_r@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
call   1060 <dbgprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <should_use_so_bsdcompat+0xe5>
mov    -0x8(%rbp),%edi
lea    0xe59(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
je     11e4 <should_use_so_bsdcompat+0xa4>
mov    -0x8(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1060 <dbgprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <should_use_so_bsdcompat+0xe5>
cmpl   $0x2,-0xc(%rbp)
ja     1202 <should_use_so_bsdcompat+0xc2>
cmpl   $0x2,-0xc(%rbp)
jne    120c <should_use_so_bsdcompat+0xcc>
cmpl   $0x5,-0x10(%rbp)
jb     120c <should_use_so_bsdcompat+0xcc>
movl   $0x1,0x2e3c(%rip)
jmp    1211 <should_use_so_bsdcompat+0xd1>
cmpl   $0x0,0x2e30(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<should_use_so_bsdcompat>:
push   %rbx
sub    $0x410,%rsp
cmpb   $0x0,0x2ef5(%rip)
je     1160 <should_use_so_bsdcompat+0x20>
movzbl 0x2ef0(%rip),%eax
xor    $0x1,%eax
jmp    11e3 <should_use_so_bsdcompat+0xa3>
movb   $0x1,0x2edd(%rip)
mov    %rsp,%rdi
call   1030 <uname@plt>
test   %rax,%rax
js     11ad <should_use_so_bsdcompat+0x6d>
mov    (%rsp),%ebx
lea    0xe8e(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11d0 <should_use_so_bsdcompat+0x90>
cmpl   $0x2,0xc(%rsp)
ja     11a4 <should_use_so_bsdcompat+0x64>
jne    1151 <should_use_so_bsdcompat+0x11>
cmpl   $0x5,0x8(%rsp)
jb     1151 <should_use_so_bsdcompat+0x11>
movb   $0x1,0x2e9d(%rip)
jmp    1151 <should_use_so_bsdcompat+0x11>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1040 <rs_strerror_r@plt>
lea    0xe34(%rip),%rdi
mov    %eax,%esi
jmp    11d9 <should_use_so_bsdcompat+0x99>
lea    0xe3b(%rip),%rdi
mov    %ebx,%esi
call   1060 <dbgprintf@plt>
mov    $0x1,%eax
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@should_use_so_bsdcompat.init_done = internal global i32 0
@should_use_so_bsdcompat.so_bsdcompat_is_obsolete = internal global i32 0
@.str = [12 x i8] c"uname: %s\0D\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%u.%u\00"
@.str.2 = [33 x i8] c"uname: unexpected release '%s'\0D\0A\00"
define i32 @should_use_so_bsdcompat() {
%1 = alloca i32
%2 = alloca %struct.utsname
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = load i32, i32* @should_use_so_bsdcompat.init_done
%7 = icmp ne i32 %6, 0
br i1 %7, label %36, label %8
8: ; preds = %0
store i32 1, i32* @should_use_so_bsdcompat.init_done
%9 = call i64 @uname(%struct.utsname* %2)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = call i32 @rs_strerror_r(i32 %12, i8* %13, i32 1024)
%15 = call i32 @dbgprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 1, i32* %1
br label %41
16: ; preds = %8
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @sscanf(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @dbgprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 1, i32* %1
br label %41
25: ; preds = %16
%26 = load i32, i32* %3
%27 = icmp ugt i32 %26, 2
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %4
%33 = icmp uge i32 %32, 5
br i1 %33, label %34, label %35
34: ; preds = %31, %25
store i32 1, i32* @should_use_so_bsdcompat.so_bsdcompat_is_obsolete
br label %35
35: ; preds = %34, %31, %28
br label %36
36: ; preds = %35, %0
%37 = load i32, i32* @should_use_so_bsdcompat.so_bsdcompat_is_obsolete
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = zext i1 %39 to i32
store i32 %40, i32* %1
br label %41
41: ; preds = %36, %21, %11
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@should_use_so_bsdcompat.init_done = internal unnamed_addr global i1 false
@should_use_so_bsdcompat.so_bsdcompat_is_obsolete = internal unnamed_addr global i1 false
@.str = [12 x i8] c"uname: %s\0D\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%u.%u\00"
@.str.2 = [33 x i8] c"uname: unexpected release '%s'\0D\0A\00"
define i32 @should_use_so_bsdcompat() {
%1 = alloca %struct.utsname
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = load i1, i1* @should_use_so_bsdcompat.init_done
br i1 %5, label %35, label %6
6: ; preds = %0
%7 = bitcast %struct.utsname* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
store i1 true, i1* @should_use_so_bsdcompat.init_done
%10 = call i64 @uname(%struct.utsname* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* @errno
%15 = call i32 @rs_strerror_r(i32 %14, i8* %13, i32 1024)
%16 = call i32 @dbgprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %34
17: ; preds = %6
%18 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @sscanf(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%21 = icmp eq i32 %20, 2
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 @dbgprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %34
24: ; preds = %17
%25 = load i32, i32* %2
%26 = icmp ugt i32 %25, 2
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = icmp eq i32 %25, 2
%29 = load i32, i32* %3
%30 = icmp ugt i32 %29, 4
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %33
32: ; preds = %27, %24
store i1 true, i1* @should_use_so_bsdcompat.so_bsdcompat_is_obsolete
br label %33
33: ; preds = %32, %27
br label %35
34: ; preds = %22, %12
br label %39
35: ; preds = %33, %0
%36 = load i1, i1* @should_use_so_bsdcompat.so_bsdcompat_is_obsolete
%37 = xor i1 %36, true
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %34, %35
%40 = phi i32 [ %38, %35 ], [ 1, %34 ]
ret i32 %40
}