#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 dell_wmi_smbios_buffer {
  int dummy;
};
typedef int __u16;

/* Variables and functions */
int find_token(int, int *, int *);
int /*<<< orphan*/ printf(char *, int);
int token_is_active(int *, int *, struct dell_wmi_smbios_buffer *);
int query_token(__u16 token, struct dell_wmi_smbios_buffer *buffer) {
  __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;
  }
  return token_is_active(&location, &value, buffer);
}


x86 assembly (clang, -O0):
<query_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <find_token@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1177 <query_token+0x47>
mov    -0x8(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118b <query_token+0x5b>
mov    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <token_is_active@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_token>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <find_token@plt>
test   %eax,%eax
je     115e <query_token+0x2e>
lea    0xeb0(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    116e <query_token+0x3e>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1040 <token_is_active@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dell_wmi_smbios_buffer = type { i32 }
@.str = [27 x i8] c"unable to find token %04x\0A\00"
define i32 @query_token(i32 %0, %struct.dell_wmi_smbios_buffer* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.dell_wmi_smbios_buffer*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store %struct.dell_wmi_smbios_buffer* %1, %struct.dell_wmi_smbios_buffer** %5
%9 = load i32, i32* %4
%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* %4
%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 %19
16: ; preds = %2
%17 = load %struct.dell_wmi_smbios_buffer*, %struct.dell_wmi_smbios_buffer** %5
%18 = call i32 @token_is_active(i32* %6, i32* %7, %struct.dell_wmi_smbios_buffer* %17)
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.dell_wmi_smbios_buffer = type { i32 }
@.str = [27 x i8] c"unable to find token %04x\0A\00"
define i32 @query_token(i32 %0, %struct.dell_wmi_smbios_buffer* %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 %0, 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 %0)
br label %13
11: ; preds = %2
%12 = call i32 @token_is_active(i32* %3, i32* %4, %struct.dell_wmi_smbios_buffer* %1)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ 1, %9 ], [ %12, %11 ]
ret i32 %14
}