#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*/ isalnum(char);
int change_dots_to_underscore(char *const str) {
  char *strp;
  int dot_count;
  strp = str;
  dot_count = 0;
  while (*strp) {
    if (*strp == '.') {
      *strp = '_';
      dot_count++;
    } else if (!isalnum(*strp) && *strp != '-') {
      return -1;
    }
    strp++;
  }
  return dot_count;
}


x86 assembly (clang, -O0):
<change_dots_to_underscore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a4 <change_dots_to_underscore+0x94>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    115d <change_dots_to_underscore+0x4d>
mov    -0x18(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <change_dots_to_underscore+0x83>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    118e <change_dots_to_underscore+0x7e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     118e <change_dots_to_underscore+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <change_dots_to_underscore+0x9a>
jmp    1193 <change_dots_to_underscore+0x83>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112b <change_dots_to_underscore+0x1b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_dots_to_underscore>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
jmp    112a <change_dots_to_underscore+0x1a>
nopw   0x0(%rax,%rax,1)
movb   $0x5f,(%rbx)
add    $0x1,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2e,%al
je     1120 <change_dots_to_underscore+0x10>
test   %al,%al
je     114b <change_dots_to_underscore+0x3b>
movsbl %al,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
jne    1126 <change_dots_to_underscore+0x16>
cmpb   $0x2d,(%rbx)
je     1126 <change_dots_to_underscore+0x16>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @change_dots_to_underscore(i8* nocapture %0) {
br label %2
2: ; preds = %14, %1
%3 = phi i8* [ %0, %1 ], [ %16, %14 ]
%4 = phi i32 [ 0, %1 ], [ %15, %14 ]
%5 = load i8, i8* %3
switch i8 %5, label %8 [
i8 0, label %17
i8 46, label %6
]
6: ; preds = %2
store i8 95, i8* %3
%7 = add nsw i32 %4, 1
br label %14
8: ; preds = %2
%9 = tail call i32 @isalnum(i8 signext %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8, i8* %3
%13 = icmp eq i8 %12, 45
br i1 %13, label %14, label %17
14: ; preds = %8, %11, %6
%15 = phi i32 [ %7, %6 ], [ %4, %8 ], [ %4, %11 ]
%16 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
17: ; preds = %2, %11
%18 = phi i32 [ -1, %11 ], [ %4, %2 ]
ret i32 %18
}