#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 atoi(char const *);
int /*<<< orphan*/ isdigit(unsigned char);
char *canonicalize_name(const char *s) {
  static char ch[2];
  if (s[0] == 'c' && s[1] == 'h' && s[2] == 'a' && s[3] == 'r') {
    const char *p;
    int n;
    for (p = s + 4; *p; p++)
      if (!(1) || !isdigit((unsigned char)*p))
        return (char *)s;
    n = atoi(s + 4);
    if (n >= 0 && n <= 0xff) {
      ch[0] = (char)n;
      return ch;
    }
  }
  return (char *)s;
}


x86 assembly (clang, -O0):
<canonicalize_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    1205 <canonicalize_name+0xe5>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
jne    1205 <canonicalize_name+0xe5>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x61,%eax
jne    1205 <canonicalize_name+0xe5>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x72,%eax
jne    1205 <canonicalize_name+0xe5>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c0 <canonicalize_name+0xa0>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11aa <canonicalize_name+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120d <canonicalize_name+0xed>
jmp    11af <canonicalize_name+0x8f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <canonicalize_name+0x5b>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1200 <canonicalize_name+0xe0>
cmpl   $0xff,-0x1c(%rbp)
jg     1200 <canonicalize_name+0xe0>
mov    -0x1c(%rbp),%eax
mov    %al,0x2e41(%rip)
lea    0x2e3a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    120d <canonicalize_name+0xed>
jmp    1205 <canonicalize_name+0xe5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonicalize_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x63,(%rdi)
jne    1184 <canonicalize_name+0x64>
cmpb   $0x68,0x1(%r14)
jne    1184 <canonicalize_name+0x64>
cmpb   $0x61,0x2(%r14)
jne    1184 <canonicalize_name+0x64>
cmpb   $0x72,0x3(%r14)
jne    1184 <canonicalize_name+0x64>
mov    0x4(%r14),%al
test   %al,%al
je     1167 <canonicalize_name+0x47>
lea    0x5(%r14),%rbx
nopl   (%rax)
movzbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1184 <canonicalize_name+0x64>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <canonicalize_name+0x30>
lea    0x4(%r14),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
ja     1184 <canonicalize_name+0x64>
mov    %al,0x2eb4(%rip)
lea    0x2ead(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@canonicalize_name.ch = internal global [2 x i8] zeroinitializer
define i8* @canonicalize_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 99
br i1 %10, label %11, label %60
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 104
br i1 %16, label %17, label %60
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 97
br i1 %22, label %23, label %60
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 114
br i1 %28, label %29, label %60
29: ; preds = %23
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 4
store i8* %31, i8** %4
br label %32
32: ; preds = %44, %29
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = call i32 @isdigit(i8 zeroext %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %36
%42 = load i8*, i8** %3
store i8* %42, i8** %2
br label %62
43: ; preds = %36
br label %44
44: ; preds = %43
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
br label %32
47: ; preds = %32
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 4
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %5
%51 = load i32, i32* %5
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %47
%54 = load i32, i32* %5
%55 = icmp sle i32 %54, 255
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %5
%58 = trunc i32 %57 to i8
store i8 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @canonicalize_name.ch, i64 0, i64 0)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @canonicalize_name.ch, i64 0, i64 0), i8** %2
br label %62
59: ; preds = %53, %47
br label %60
60: ; preds = %59, %23, %17, %11, %1
%61 = load i8*, i8** %3
store i8* %61, i8** %2
br label %62
62: ; preds = %60, %56, %41
%63 = load i8*, i8** %2
ret i8* %63
}

LLVM IR (-O2):
@canonicalize_name.ch = internal global [2 x i8] zeroinitializer
define i8* @canonicalize_name(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 99
br i1 %3, label %4, label %34
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 104
br i1 %7, label %8, label %34
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 97
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 114
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %29, label %23
20: ; preds = %23
%21 = load i8, i8* %28
%22 = icmp eq i8 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %16, %20
%24 = phi i8 [ %21, %20 ], [ %18, %16 ]
%25 = phi i8* [ %28, %20 ], [ %17, %16 ]
%26 = tail call i32 @isdigit(i8 zeroext %24)
%27 = icmp eq i32 %26, 0
%28 = getelementptr inbounds i8, i8* %25, i64 1
br i1 %27, label %34, label %20
29: ; preds = %20, %16
%30 = tail call i32 @atoi(i8* %17)
%31 = icmp ult i32 %30, 256
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = trunc i32 %30 to i8
store i8 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @canonicalize_name.ch, i64 0, i64 0)
br label %34
34: ; preds = %23, %32, %1, %4, %8, %12, %29
%35 = phi i8* [ %0, %29 ], [ %0, %12 ], [ %0, %8 ], [ %0, %4 ], [ %0, %1 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @canonicalize_name.ch, i64 0, i64 0), %32 ], [ %0, %23 ]
ret i8* %35
}