#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int *input;
  int /*<<< orphan*/ cmd_select;
  int /*<<< orphan*/ cmd_class;
};
struct dell_wmi_smbios_buffer {
  TYPE_1__ std;
};
typedef int __u16;

/* Variables and functions */
int /*<<< orphan*/ CLASS_TOKEN_WRITE;
int /*<<< orphan*/ SELECT_TOKEN_STD;
int find_token(int, int *, int *);
int /*<<< orphan*/ printf(char *, int);
int run_wmi_smbios_cmd(struct dell_wmi_smbios_buffer *);
int activate_token(struct dell_wmi_smbios_buffer *buffer, __u16 token) {
  __u16 location;
  __u16 value;
  int ret;
  ret = find_token(token, &location, &value);
  if (ret != 0) {
    printf("unable to find token %04x\n", token);
    return 1;
  }
  buffer->std.cmd_class = CLASS_TOKEN_WRITE;
  buffer->std.cmd_select = SELECT_TOKEN_STD;
  buffer->std.input[0] = location;
  buffer->std.input[1] = 1;
  ret = run_wmi_smbios_cmd(buffer);
  return ret;
}


x86 assembly (clang, -O0):
<activate_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <find_token@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1177 <activate_token+0x47>
mov    -0x14(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c3 <activate_token+0x93>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    0x2e62(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <run_wmi_smbios_cmd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<activate_token>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1030 <find_token@plt>
test   %eax,%eax
je     1160 <activate_token+0x30>
lea    0xeae(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    118f <activate_token+0x5f>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rbx)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    (%rsp),%eax
mov    (%rbx),%rcx
mov    %eax,(%rcx)
movl   $0x1,0x4(%rcx)
mov    %rbx,%rdi
call   1050 <run_wmi_smbios_cmd@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dell_wmi_smbios_buffer = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32*, i32, i32 }
@.str = [27 x i8] c"unable to find token %04x\0A\00"
@CLASS_TOKEN_WRITE = global i32 0
@SELECT_TOKEN_STD = global i32 0
define i32 @activate_token(%struct.dell_wmi_smbios_buffer* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.dell_wmi_smbios_buffer*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.dell_wmi_smbios_buffer* %0, %struct.dell_wmi_smbios_buffer** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = call i32 @find_token(i32 %9, i32* %6, i32* %7)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %5
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 1, i32* %3
br label %39
16: ; preds = %2
%17 = load i32, i32* @CLASS_TOKEN_WRITE
%18 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %4
%19 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %18, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 2
store i32 %17, i32* %20
%21 = load i32, i32* @SELECT_TOKEN_STD
%22 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %4
%23 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %22, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 1
store i32 %21, i32* %24
%25 = load i32, i32* %6
%26 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %4
%27 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i32*, i32** %28
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 %25, i32* %30
%31 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %4
%32 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %31, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
%34 = load i32*, i32** %33
%35 = getelementptr inbounds i32, i32* %34, i64 1
store i32 1, i32* %35
%36 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %4
%37 = call i32 @run_wmi_smbios_cmd(%struct.dell_wmi_smbios_buffer* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
store i32 %38, i32* %3
br label %39
39: ; preds = %16, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.dell_wmi_smbios_buffer = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32*, i32, i32 }
@.str = [27 x i8] c"unable to find token %04x\0A\00"
@CLASS_TOKEN_WRITE = global i32 0
@SELECT_TOKEN_STD = global i32 0
define i32 @activate_token(%struct.dell_wmi_smbios_buffer* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @find_token(i32 %1, i32* %3, i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %21
11: ; preds = %2
%12 = load i32, i32* @CLASS_TOKEN_WRITE
%13 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %0, i64 0, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @SELECT_TOKEN_STD
%15 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %0, i64 0, i32 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* %3
%17 = getelementptr inbounds %struct.dell_wmi_smbios_buffer, %struct.dell_wmi_smbios_buffer* %0, i64 0, i32 0, i32 0
%18 = load i32*, i32** %17
store i32 %16, i32* %18
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 1, i32* %19
%20 = call i32 @run_wmi_smbios_cmd(%struct.dell_wmi_smbios_buffer* %0)
br label %21
21: ; preds = %11, %9
%22 = phi i32 [ 1, %9 ], [ %20, %11 ]
ret i32 %22
}