#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__ isalnum(char);
int validate_name(int flag, char *name) {
  char *p;
  int x;
  if (flag == 3)
    x = '.';
  else
    x = '-';
  for (p = name; *p; p++) {
    if (isalnum(*p) || (*p == '-') || (*p == x))
      continue;
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<validate_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1135 <validate_name+0x25>
movl   $0x2e,-0x1c(%rbp)
jmp    113c <validate_name+0x2c>
movl   $0x2d,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a9 <validate_name+0x99>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
jne    1187 <validate_name+0x77>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1187 <validate_name+0x77>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x1c(%rbp),%eax
jne    118c <validate_name+0x7c>
jmp    1198 <validate_name+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <validate_name+0xa0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <validate_name+0x34>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_name>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
cmp    $0x3,%edi
sete   %cl
mov    (%rsi),%al
mov    $0x1,%r14d
test   %al,%al
je     1168 <validate_name+0x58>
mov    %rsi,%rbx
mov    %cl,%bpl
add    $0x2d,%ebp
add    $0x1,%rbx
jmp    114b <validate_name+0x3b>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1168 <validate_name+0x58>
movsbl %al,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
jne    1140 <validate_name+0x30>
movsbl -0x1(%rbx),%eax
cmp    $0x2d,%eax
je     1140 <validate_name+0x30>
cmp    %eax,%ebp
je     1140 <validate_name+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @validate_name(i32 %0, i8* nocapture %1) {
%3 = icmp eq i32 %0, 3
%4 = select i1 %3, i32 46, i32 45
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %2, %18
%8 = phi i8 [ %20, %18 ], [ %5, %2 ]
%9 = phi i8* [ %19, %18 ], [ %1, %2 ]
%10 = tail call i64 @isalnum(i8 signext %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i8, i8* %9
%14 = icmp eq i8 %13, 45
%15 = sext i8 %13 to i32
%16 = icmp eq i32 %4, %15
%17 = or i1 %14, %16
br i1 %17, label %18, label %22
18: ; preds = %7, %12
%19 = getelementptr inbounds i8, i8* %9, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %7
22: ; preds = %12, %18, %2
%23 = phi i32 [ 1, %2 ], [ 1, %18 ], [ 0, %12 ]
ret i32 %23
}