#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 */
scalar_t__ strcmp(char *, char const *);
int strlen(char *);
char toupper(char);
int MatchDeviceName(char *targetName, const char *detectedName) {
  int i;
  if (targetName) {
    for (i = 0; i < strlen(targetName); i++) {
      targetName[i] = toupper(targetName[i]);
    }
  }
  return (!targetName || (strcmp(targetName, detectedName) == 0));
}


x86 assembly (clang, -O0):
<MatchDeviceName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119f <MatchDeviceName+0x6f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    119a <MatchDeviceName+0x6a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <MatchDeviceName+0x22>
jmp    119f <MatchDeviceName+0x6f>
mov    $0x1,%al
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     11c6 <MatchDeviceName+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatchDeviceName>:
test   %rdi,%rdi
je     118d <MatchDeviceName+0x5d>
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    1171 <MatchDeviceName+0x41>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <MatchDeviceName+0x20>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @MatchDeviceName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %29
8: ; preds = %2
store i32 0, i32* %5
br label %9
9: ; preds = %25, %8
%10 = load i32, i32* %5
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %28
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call signext i8 @toupper(i8 signext %19)
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %9
28: ; preds = %9
br label %29
29: ; preds = %28, %2
%30 = load i8*, i8** %3
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8*, i8** %3
%34 = load i8*, i8** %4
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp eq i64 %35, 0
br label %37
37: ; preds = %32, %29
%38 = phi i1 [ true, %29 ], [ %36, %32 ]
%39 = zext i1 %38 to i32
ret i32 %39
}

LLVM IR (-O2):
define i32 @MatchDeviceName(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4, %7
%8 = phi i64 [ %12, %7 ], [ 0, %4 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call signext i8 @toupper(i8 signext %10)
store i8 %11, i8* %9
%12 = add nuw nsw i64 %8, 1
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %12, %14
br i1 %15, label %7, label %16
16: ; preds = %7, %4
%17 = tail call i64 @strcmp(i8* %0, i8* %1)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %2, %16
%21 = phi i32 [ %19, %16 ], [ 1, %2 ]
ret i32 %21
}