#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 */

/* Variables and functions */
int /*<<< orphan*/ EVIOCGNAME(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char **);
int /*<<< orphan*/ strcmp(char const *, char *);
const char *get_powermate_model(int fd) {
  unsigned int index;
  char id_buff[256];
  const char *id_strings[] = {"Griffin SoundKnob", "Griffin PowerMate"};
  ioctl(fd, EVIOCGNAME(255), &id_buff);
  for (index = 0; index != 2; index++)
    if (!strcmp(id_strings[index], id_buff))
      return id_strings[index];
  return NULL;
}


x86 assembly (clang, -O0):
<get_powermate_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2ccb(%rip),%rax
mov    %rax,-0x120(%rbp)
mov    0x2cc5(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    $0xff,%edi
call   1050 <EVIOCGNAME@plt>
mov    -0x124(%rbp),%edi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
call   1030 <ioctl@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
je     11d9 <get_powermate_model+0xa9>
mov    -0x10(%rbp),%eax
mov    -0x120(%rbp,%rax,8),%rdi
ff
lea    -0x110(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c6 <get_powermate_model+0x96>
mov    -0x10(%rbp),%eax
mov    -0x120(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
jmp    11e1 <get_powermate_model+0xb1>
jmp    11cb <get_powermate_model+0x9b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1188 <get_powermate_model+0x58>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_powermate_model>:
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
mov    $0xff,%edi
call   1040 <EVIOCGNAME@plt>
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <ioctl@plt>
movdqa (%rsp),%xmm0
movzwl 0x10(%rsp),%eax
movd   %eax,%xmm1
pcmpeqb 0xeaa(%rip),%xmm0
pcmpeqb 0xeb2(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%eax
cmp    $0xffff,%eax
je     11a8 <get_powermate_model+0x88>
movdqa (%rsp),%xmm0
movzwl 0x10(%rsp),%eax
movd   %eax,%xmm1
pcmpeqb 0xe9d(%rip),%xmm0
pcmpeqb 0xea5(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%ecx
xor    %eax,%eax
cmp    $0xffff,%ecx
lea    0xeb0(%rip),%rcx
cmove  %rcx,%rax
jmp    11af <get_powermate_model+0x8f>
lea    0xe91(%rip),%rax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Griffin SoundKnob\00"
@.str.1 = [18 x i8] c"Griffin PowerMate\00"
@__const.get_powermate_model.id_strings = [2 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i32 0, i32 0)]
define i8* @get_powermate_model(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [2 x i8*]
store i32 %0, i32* %3
%7 = bitcast [2 x i8*]* %6 to i8*
%8 = load i32, i32* %3
%9 = call i32 @EVIOCGNAME(i32 255)
%10 = bitcast [256 x i8]* %5 to i8**
%11 = call i32 @ioctl(i32 %8, i32 %9, i8** %10)
store i32 0, i32* %4
br label %12
12: ; preds = %29, %1
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %15
%24 = load i32, i32* %4
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %25
%27 = load i8*, i8** %26
store i8* %27, i8** %2
br label %33
28: ; preds = %15
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add i32 %30, 1
store i32 %31, i32* %4
br label %12
32: ; preds = %12
store i8* null, i8** %2
br label %33
33: ; preds = %32, %23
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [18 x i8] c"Griffin SoundKnob\00"
@.str.1 = [18 x i8] c"Griffin PowerMate\00"
define i8* @get_powermate_model(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @EVIOCGNAME(i32 255)
%5 = bitcast [256 x i8]* %2 to i8**
%6 = call i32 @ioctl(i32 %0, i32 %4, i8** %5)
%7 = call i32 @bcmp(i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(18) %3, i64 18)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = call i32 @bcmp(i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(18) %3, i64 18)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* null
br label %13
13: ; preds = %9, %1
%14 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %1 ], [ %12, %9 ]
ret i8* %14
}