#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 binder_version {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ BINDER_VERSION;
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct binder_version *);
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *binder_version_thread(void *data) {
  int fd = ((int)((intptr_t)(data)));
  struct binder_version version = {0};
  int ret;
  ret = ioctl(fd, BINDER_VERSION, &version);
  if (ret < 0)
    ksft_print_msg("%s - Failed to open perform BINDER_VERSION request\n",
                   strerror(errno));
  pthread_exit(data);
}


x86 assembly (clang, -O0):
<binder_version_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b1 <binder_version_thread+0x61>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe54(%rip),%rdi
call   1060 <ksft_print_msg@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binder_version_thread>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0x8(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
jns    1183 <binder_version_thread+0x43>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
call   1050 <ksft_print_msg@plt>
mov    %rbx,%rdi
call   1040 <pthread_exit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.binder_version = type { i32 }
@BINDER_VERSION = global i32 0
@.str = [52 x i8] c"%s - Failed to open perform BINDER_VERSION request\0A\00"
@errno = global i32 0
define i8* @binder_version_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.binder_version
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
store i32 %9, i32* %4
%10 = bitcast %struct.binder_version* %5 to i8*
%11 = load i32, i32* %4
%12 = load i32, i32* @BINDER_VERSION
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.binder_version* %5)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %1
%21 = load i8*, i8** %3
%22 = call i32 @pthread_exit(i8* %21)
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.binder_version = type { i32 }
@BINDER_VERSION = global i32 0
@.str = [52 x i8] c"%s - Failed to open perform BINDER_VERSION request\0A\00"
@errno = global i32 0
define noalias i8* @binder_version_thread(i8* %0) {
%2 = alloca %struct.binder_version
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = bitcast %struct.binder_version* %2 to i8*
%6 = getelementptr inbounds %struct.binder_version, %struct.binder_version* %2, i64 0, i32 0
store i32 0, i32* %6
%7 = load i32, i32* @BINDER_VERSION
%8 = call i32 @ioctl(i32 %4, i32 %7, %struct.binder_version* %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %1
%15 = call i32 @pthread_exit(i8* %0)
ret i8* undef
}