#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 const *, char *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
char tolower(char const);
extern const char *Unix_MatchValidSerialDevice(const char *name) {
  int i = 0;
  char *sername = NULL;
  if (name == NULL) {
    return "/dev/ttyS0";
  }
  if (strlen(name) == strlen("/dev/ttyS0") &&
      strncmp(name, "/dev/ttyS", strlen("/dev/ttyS")) == 0) {
    return name;
  }
  if (strcmp(name, "1") == 0 || strcmp(name, "S") == 0 ||
      strcmp(name, "s") == 0) {
    return "/dev/ttyS0";
  }
  if (strcmp(name, "2") == 0)
    return "/dev/ttyS1";
  do {
    switch (name[i]) {
    case ',':
      i++;
      break;
    default:
      return 0;
    case 0:
      return sername;
    case 's':
    case 'S':
    case 'h':
    case 'H': {
      char ch = tolower(name[i]);
      int j, continue_from, len;
      if (name[++i] == 0 || name[i] == ',') {
        if (ch == 's')
          sername = "/dev/ttyS0";
        break;
      }
      if (name[i] != '=')
        return 0;
      for (j = ++i; name[j] != 0 && name[j] != ','; j++)
        ;
      if (name[j] == '0')
        continue_from = -1;
      else
        continue_from = j;
      len = (j - i);
      switch (ch) {
      case 's': {
        if (len == 1) {
          if (name[i] == '1')
            sername = "/dev/ttyS0";
          else if (name[i] == '2')
            sername = "/dev/ttyS1";
        } else if (len == strlen("/dev/ttyS0")) {
          if (strncmp(name + i, "/dev/ttyS0", strlen("/dev/ttyS0")) == 0)
            sername = "/dev/ttyS0";
          else if (strncmp(name + i, "/dev/ttyS1", strlen("/dev/ttyS1")) == 0)
            sername = "/dev/ttyS1";
        }
        break;
      }
      case 'h':
        break;
      }
      if (continue_from == -1)
        return sername;
      i = continue_from;
      break;
    }
    }
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<Unix_MatchValidSerialDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <Unix_MatchValidSerialDevice+0x36>
lea    0xe93(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jne    11d8 <Unix_MatchValidSerialDevice+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe61(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe4f(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d8 <Unix_MatchValidSerialDevice+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1226 <Unix_MatchValidSerialDevice+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1226 <Unix_MatchValidSerialDevice+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1236 <Unix_MatchValidSerialDevice+0xf6>
lea    0xdd3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x10(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <Unix_MatchValidSerialDevice+0x120>
lea    0xdc2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
jmp    1265 <Unix_MatchValidSerialDevice+0x125>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x44(%rbp)
test   %eax,%eax
je     12f1 <Unix_MatchValidSerialDevice+0x1b1>
jmp    1281 <Unix_MatchValidSerialDevice+0x141>
mov    -0x44(%rbp),%eax
sub    $0x2c,%eax
je     12d6 <Unix_MatchValidSerialDevice+0x196>
jmp    1292 <Unix_MatchValidSerialDevice+0x152>
mov    -0x44(%rbp),%eax
sub    $0x48,%eax
je     12fe <Unix_MatchValidSerialDevice+0x1be>
jmp    12a3 <Unix_MatchValidSerialDevice+0x163>
mov    -0x44(%rbp),%eax
sub    $0x53,%eax
je     12fe <Unix_MatchValidSerialDevice+0x1be>
jmp    12b4 <Unix_MatchValidSerialDevice+0x174>
mov    -0x44(%rbp),%eax
sub    $0x68,%eax
je     12fe <Unix_MatchValidSerialDevice+0x1be>
jmp    12c5 <Unix_MatchValidSerialDevice+0x185>
mov    -0x44(%rbp),%eax
sub    $0x73,%eax
je     12fe <Unix_MatchValidSerialDevice+0x1be>
jmp    12e4 <Unix_MatchValidSerialDevice+0x1a4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1570 <Unix_MatchValidSerialDevice+0x430>
movq   $0x0,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1344 <Unix_MatchValidSerialDevice+0x204>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    1361 <Unix_MatchValidSerialDevice+0x221>
movsbl -0x21(%rbp),%eax
cmp    $0x73,%eax
jne    135c <Unix_MatchValidSerialDevice+0x21c>
lea    0xca8(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1570 <Unix_MatchValidSerialDevice+0x430>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     1383 <Unix_MatchValidSerialDevice+0x243>
movq   $0x0,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x45(%rbp)
je     13be <Unix_MatchValidSerialDevice+0x27e>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
setne  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    13ce <Unix_MatchValidSerialDevice+0x28e>
jmp    13e1 <Unix_MatchValidSerialDevice+0x2a1>
jmp    13d3 <Unix_MatchValidSerialDevice+0x293>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    138f <Unix_MatchValidSerialDevice+0x24f>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    1402 <Unix_MatchValidSerialDevice+0x2c2>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1408 <Unix_MatchValidSerialDevice+0x2c8>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x68,%eax
je     154e <Unix_MatchValidSerialDevice+0x40e>
jmp    1428 <Unix_MatchValidSerialDevice+0x2e8>
mov    -0x4c(%rbp),%eax
sub    $0x73,%eax
jne    1553 <Unix_MatchValidSerialDevice+0x413>
jmp    1439 <Unix_MatchValidSerialDevice+0x2f9>
cmpl   $0x1,-0x30(%rbp)
jne    1492 <Unix_MatchValidSerialDevice+0x352>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1468 <Unix_MatchValidSerialDevice+0x328>
lea    0xba1(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    148d <Unix_MatchValidSerialDevice+0x34d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x32,%eax
jne    1488 <Unix_MatchValidSerialDevice+0x348>
lea    0xb95(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    148d <Unix_MatchValidSerialDevice+0x34d>
jmp    1549 <Unix_MatchValidSerialDevice+0x409>
mov    -0x30(%rbp),%eax
mov    %eax,-0x50(%rbp)
lea    0xb61(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
cmp    %ecx,%eax
jne    1544 <Unix_MatchValidSerialDevice+0x404>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
lea    0xb39(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xb27(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14f8 <Unix_MatchValidSerialDevice+0x3b8>
lea    0xb11(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    153f <Unix_MatchValidSerialDevice+0x3ff>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
lea    0xb0b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
lea    0xaf9(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    153a <Unix_MatchValidSerialDevice+0x3fa>
lea    0xae3(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    153f <Unix_MatchValidSerialDevice+0x3ff>
jmp    1544 <Unix_MatchValidSerialDevice+0x404>
jmp    1549 <Unix_MatchValidSerialDevice+0x409>
jmp    1553 <Unix_MatchValidSerialDevice+0x413>
jmp    1553 <Unix_MatchValidSerialDevice+0x413>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    156a <Unix_MatchValidSerialDevice+0x42a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    158c <Unix_MatchValidSerialDevice+0x44c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1575 <Unix_MatchValidSerialDevice+0x435>
mov    $0x1,%al
test   $0x1,%al
jne    1265 <Unix_MatchValidSerialDevice+0x125>
jmp    1584 <Unix_MatchValidSerialDevice+0x444>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Unix_MatchValidSerialDevice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     120f <Unix_MatchValidSerialDevice+0xcf>
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe9b(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    1196 <Unix_MatchValidSerialDevice+0x56>
lea    0xe93(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     121b <Unix_MatchValidSerialDevice+0xdb>
lea    0xe85(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     135b <Unix_MatchValidSerialDevice+0x21b>
lea    0xe5e(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     135b <Unix_MatchValidSerialDevice+0x21b>
lea    0xe48(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     135b <Unix_MatchValidSerialDevice+0x21b>
lea    0xe32(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1350 <Unix_MatchValidSerialDevice+0x210>
movabs $0x80100000801,%r13
lea    0xdf9(%rip),%rbp
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1235 <Unix_MatchValidSerialDevice+0xf5>
lea    0xdea(%rip),%rbx
jmp    135b <Unix_MatchValidSerialDevice+0x21b>
mov    %r12,%rbx
jmp    135b <Unix_MatchValidSerialDevice+0x21b>
cmp    $0x2c,%dl
jne    1359 <Unix_MatchValidSerialDevice+0x219>
cmp    $0x73,%al
cmove  %rbp,%r15
mov    %ecx,%r14d
movslq %r14d,%rbx
lea    0x2(%rbx),%r14d
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
cmp    $0x2c,%edi
jne    1260 <Unix_MatchValidSerialDevice+0x120>
add    $0x1,%rbx
add    $0x1,%r14d
jmp    1240 <Unix_MatchValidSerialDevice+0x100>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x48(%rdi),%eax
cmp    $0x2b,%eax
ja     1347 <Unix_MatchValidSerialDevice+0x207>
bt     %rax,%r13
jae    1347 <Unix_MatchValidSerialDevice+0x207>
call   1060 <tolower@plt>
lea    0x1(%rbx),%rcx
movslq %ecx,%rdx
mov    (%r12,%rdx,1),%dl
test   %dl,%dl
je     122c <Unix_MatchValidSerialDevice+0xec>
cmp    $0x3d,%dl
jne    1223 <Unix_MatchValidSerialDevice+0xe3>
add    $0x2,%ebx
movslq %ebx,%r13
movslq %r14d,%rcx
add    %r12,%rcx
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%rcx,%rbx,1),%edx
test   %dl,%dl
je     12b7 <Unix_MatchValidSerialDevice+0x177>
cmp    $0x2c,%dl
je     12b7 <Unix_MatchValidSerialDevice+0x177>
add    $0x1,%r14d
add    $0x1,%rbx
jmp    12a0 <Unix_MatchValidSerialDevice+0x160>
cmp    $0x73,%al
jne    132b <Unix_MatchValidSerialDevice+0x1eb>
cmp    $0x1,%ebx
jne    12d8 <Unix_MatchValidSerialDevice+0x198>
mov    (%r12,%r13,1),%al
mov    %rbp,%rbx
cmp    $0x31,%al
je     132e <Unix_MatchValidSerialDevice+0x1ee>
cmp    $0x32,%al
jne    132b <Unix_MatchValidSerialDevice+0x1eb>
lea    0xd43(%rip),%rbx
jmp    132e <Unix_MatchValidSerialDevice+0x1ee>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jne    132b <Unix_MatchValidSerialDevice+0x1eb>
add    %r12,%r13
lea    0xd12(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     132e <Unix_MatchValidSerialDevice+0x1ee>
lea    0xd0a(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
cmove  %rbx,%r15
mov    %r15,%rbx
mov    %rbx,%r15
cmp    $0xffffffff,%r14d
movabs $0x80100000801,%r13
jne    1235 <Unix_MatchValidSerialDevice+0xf5>
jmp    135b <Unix_MatchValidSerialDevice+0x21b>
test   %edi,%edi
jne    1359 <Unix_MatchValidSerialDevice+0x219>
mov    %r15,%rbx
jmp    135b <Unix_MatchValidSerialDevice+0x21b>
lea    0xcc2(%rip),%rbx
jmp    135b <Unix_MatchValidSerialDevice+0x21b>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [10 x i8] c"/dev/ttyS\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [2 x i8] c"S\00"
@.str.4 = [2 x i8] c"s\00"
@.str.5 = [2 x i8] c"2\00"
@.str.6 = [11 x i8] c"/dev/ttyS1\00"
define i8* @Unix_MatchValidSerialDevice(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i8* null, i8** %5
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
br label %197
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i8*, i8** %3
store i8* %24, i8** %2
br label %197
25: ; preds = %18, %13
%26 = load i8*, i8** %3
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33, %29, %25
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
br label %197
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %197
43: ; preds = %38
br label %44
44: ; preds = %195, %43
%45 = load i8*, i8** %3
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
switch i32 %50, label %54 [
i32 44, label %51
i32 0, label %55
i32 115, label %57
i32 83, label %57
i32 104, label %57
i32 72, label %57
]
51: ; preds = %44
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %194
54: ; preds = %44
store i8* null, i8** %2
br label %197
55: ; preds = %44
%56 = load i8*, i8** %5
store i8* %56, i8** %2
br label %197
57: ; preds = %44, %44, %44, %44
%58 = load i8*, i8** %3
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = call signext i8 @tolower(i8 signext %62)
store i8 %63, i8* %6
%64 = load i8*, i8** %3
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 0
br i1 %71, label %80, label %72
72: ; preds = %57
%73 = load i8*, i8** %3
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 44
br i1 %79, label %80, label %86
80: ; preds = %72, %57
%81 = load i8, i8* %6
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 115
br i1 %83, label %84, label %85
84: ; preds = %80
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %5
br label %85
85: ; preds = %84, %80
br label %194
86: ; preds = %72
%87 = load i8*, i8** %3
%88 = load i32, i32* %4
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp ne i32 %92, 61
br i1 %93, label %94, label %95
94: ; preds = %86
store i8* null, i8** %2
br label %197
95: ; preds = %86
%96 = load i32, i32* %4
%97 = add nsw i32 %96, 1
store i32 %97, i32* %4
store i32 %97, i32* %7
br label %98
98: ; preds = %117, %95
%99 = load i8*, i8** %3
%100 = load i32, i32* %7
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %98
%107 = load i8*, i8** %3
%108 = load i32, i32* %7
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp ne i32 %112, 44
br label %114
114: ; preds = %106, %98
%115 = phi i1 [ false, %98 ], [ %113, %106 ]
br i1 %115, label %116, label %120
116: ; preds = %114
br label %117
117: ; preds = %116
%118 = load i32, i32* %7
%119 = add nsw i32 %118, 1
store i32 %119, i32* %7
br label %98
120: ; preds = %114
%121 = load i8*, i8** %3
%122 = load i32, i32* %7
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* %121, i64 %123
%125 = load i8, i8* %124
%126 = sext i8 %125 to i32
%127 = icmp eq i32 %126, 48
br i1 %127, label %128, label %129
128: ; preds = %120
store i32 -1, i32* %8
br label %131
129: ; preds = %120
%130 = load i32, i32* %7
store i32 %130, i32* %8
br label %131
131: ; preds = %129, %128
%132 = load i32, i32* %7
%133 = load i32, i32* %4
%134 = sub nsw i32 %132, %133
store i32 %134, i32* %9
%135 = load i8, i8* %6
%136 = sext i8 %135 to i32
switch i32 %136, label %187 [
i32 115, label %137
i32 104, label %186
]
137: ; preds = %131
%138 = load i32, i32* %9
%139 = icmp eq i32 %138, 1
br i1 %139, label %140, label %160
140: ; preds = %137
%141 = load i8*, i8** %3
%142 = load i32, i32* %4
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8, i8* %141, i64 %143
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = icmp eq i32 %146, 49
br i1 %147, label %148, label %149
148: ; preds = %140
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %5
br label %159
149: ; preds = %140
%150 = load i8*, i8** %3
%151 = load i32, i32* %4
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8, i8* %150, i64 %152
%154 = load i8, i8* %153
%155 = sext i8 %154 to i32
%156 = icmp eq i32 %155, 50
br i1 %156, label %157, label %158
157: ; preds = %149
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %5
br label %158
158: ; preds = %157, %149
br label %159
159: ; preds = %158, %148
br label %185
160: ; preds = %137
%161 = load i32, i32* %9
%162 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%163 = icmp eq i32 %161, %162
br i1 %163, label %164, label %184
164: ; preds = %160
%165 = load i8*, i8** %3
%166 = load i32, i32* %4
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %165, i64 %167
%169 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%170 = call i64 @strncmp(i8* %168, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %169)
%171 = icmp eq i64 %170, 0
br i1 %171, label %172, label %173
172: ; preds = %164
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %5
br label %183
173: ; preds = %164
%174 = load i8*, i8** %3
%175 = load i32, i32* %4
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i8, i8* %174, i64 %176
%178 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%179 = call i64 @strncmp(i8* %177, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %178)
%180 = icmp eq i64 %179, 0
br i1 %180, label %181, label %182
181: ; preds = %173
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %5
br label %182
182: ; preds = %181, %173
br label %183
183: ; preds = %182, %172
br label %184
184: ; preds = %183, %160
br label %185
185: ; preds = %184, %159
br label %187
186: ; preds = %131
br label %187
187: ; preds = %131, %186, %185
%188 = load i32, i32* %8
%189 = icmp eq i32 %188, -1
br i1 %189, label %190, label %192
190: ; preds = %187
%191 = load i8*, i8** %5
store i8* %191, i8** %2
br label %197
192: ; preds = %187
%193 = load i32, i32* %8
store i32 %193, i32* %4
br label %194
194: ; preds = %192, %85, %51
br label %195
195: ; preds = %194
br i1 true, label %44, label %196
196: ; preds = %195
store i8* null, i8** %2
br label %197
197: ; preds = %196, %190, %94, %55, %54, %42, %37, %23, %12
%198 = load i8*, i8** %2
ret i8* %198
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [10 x i8] c"/dev/ttyS\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [2 x i8] c"S\00"
@.str.4 = [2 x i8] c"s\00"
@.str.5 = [2 x i8] c"2\00"
@.str.6 = [11 x i8] c"/dev/ttyS1\00"
define i8* @Unix_MatchValidSerialDevice(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %84, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %84, label %11
11: ; preds = %7, %3
%12 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %84, label %14
14: ; preds = %11
%15 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %84, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %84, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %84, label %23
23: ; preds = %20, %79
%24 = phi i8* [ %80, %79 ], [ null, %20 ]
%25 = phi i32 [ %81, %79 ], [ 0, %20 ]
br label %26
26: ; preds = %23, %32
%27 = phi i32 [ %33, %32 ], [ %25, %23 ]
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
switch i32 %31, label %82 [
i32 44, label %32
i32 0, label %84
i32 115, label %34
i32 83, label %34
i32 104, label %34
i32 72, label %34
]
32: ; preds = %26
%33 = add nsw i32 %27, 1
br label %26
34: ; preds = %26, %26, %26, %26
%35 = tail call signext i8 @tolower(i8 signext %30)
%36 = add nsw i32 %27, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
switch i8 %39, label %82 [
i8 0, label %40
i8 44, label %40
i8 61, label %43
]
40: ; preds = %34, %34
%41 = icmp eq i8 %35, 115
%42 = select i1 %41, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %24
br label %79
43: ; preds = %34
%44 = add i32 %27, 2
%45 = sext i32 %44 to i64
br label %46
46: ; preds = %50, %43
%47 = phi i64 [ %51, %50 ], [ %45, %43 ]
%48 = getelementptr inbounds i8, i8* %0, i64 %47
%49 = load i8, i8* %48
switch i8 %49, label %50 [
i8 0, label %52
i8 44, label %52
]
50: ; preds = %46
%51 = add i64 %47, 1
br label %46
52: ; preds = %46, %46
%53 = trunc i64 %47 to i32
%54 = sub nsw i32 %53, %44
%55 = icmp eq i8 %35, 115
br i1 %55, label %56, label %76
56: ; preds = %52
%57 = icmp eq i32 %54, 1
br i1 %57, label %58, label %62
58: ; preds = %56
%59 = getelementptr inbounds i8, i8* %0, i64 %45
%60 = load i8, i8* %59
switch i8 %60, label %75 [
i8 49, label %76
i8 50, label %61
]
61: ; preds = %58
br label %76
62: ; preds = %56
%63 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%64 = icmp eq i32 %54, %63
br i1 %64, label %65, label %76
65: ; preds = %62
%66 = getelementptr inbounds i8, i8* %0, i64 %45
%67 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%68 = tail call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %76, label %70
70: ; preds = %65
%71 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%72 = tail call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = icmp eq i64 %72, 0
%74 = select i1 %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %24
br label %76
75: ; preds = %58
br label %76
76: ; preds = %52, %62, %61, %75, %58, %65, %70
%77 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %61 ], [ %24, %62 ], [ %24, %52 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %58 ], [ %24, %75 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %65 ], [ %74, %70 ]
%78 = icmp eq i32 %53, -1
br i1 %78, label %82, label %79
79: ; preds = %76, %40
%80 = phi i8* [ %42, %40 ], [ %77, %76 ]
%81 = phi i32 [ %36, %40 ], [ %53, %76 ]
br label %23
82: ; preds = %76, %34, %26
%83 = phi i8* [ null, %26 ], [ %77, %76 ], [ null, %34 ]
br label %84
84: ; preds = %26, %82, %20, %11, %14, %17, %7, %1
%85 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %1 ], [ %0, %7 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %17 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %14 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %20 ], [ %83, %82 ], [ %24, %26 ]
ret i8* %85
}