#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 *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char);
char *strchr(char *, char);
int next_name(char *str) {
  char *p;
  int next;
  p = strchr(str, '.');
  if (p == NULL) {
    printf("\n\tFilename %s should contain a dot\n", str);
    exit(1);
  }
  p++;
  if (*p == '\000') {
    *p = '0';
    *(p + 1) = '\000';
  } else {
    next = atoi(p);
    next++;
    sprintf(p, "%d%c", next, '\000');
  }
  return next;
}


x86 assembly (clang, -O0):
<next_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <next_name+0x43>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c3 <next_name+0x73>
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11ed <next_name+0x9d>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe3e(%rip),%rsi
xor    %ecx,%ecx
call   1060 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_name>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a3 <next_name+0x53>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
je     1194 <next_name+0x44>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
add    $0x1,%ebp
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1060 <sprintf@plt>
jmp    119a <next_name+0x4a>
movw   $0x30,0x1(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe56(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"\0A\09Filename %s should contain a dot\0A\00"
@.str.1 = [5 x i8] c"%d%c\00"
define i32 @next_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 46)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8*, i8** %3
store i8 48, i8* %21
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
br label %32
24: ; preds = %13
%25 = load i8*, i8** %3
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8 signext 0)
br label %32
32: ; preds = %24, %20
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [36 x i8] c"\0A\09Filename %s should contain a dot\0A\00"
@.str.1 = [5 x i8] c"%d%c\00"
define i32 @next_name(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
store i8 48, i8* %8
%12 = getelementptr inbounds i8, i8* %2, i64 2
store i8 0, i8* %12
br label %17
13: ; preds = %7
%14 = tail call i32 @atoi(i8* %8)
%15 = add nsw i32 %14, 1
%16 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8 signext 0)
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ undef, %11 ], [ %15, %13 ]
ret i32 %18
}