#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__ isdigit(char);
int strlen(char *);
char *strrchr(char *, char);
void os_set_filenumber(char *NewName, int Size, int n) {
  char *p;
  int i;
  p = strrchr(NewName, '/');
  if (p == NULL)
    p = NewName;
  for (i = strlen(p) - 1; i >= 0; i--) {
    if (isdigit(p[i])) {
      p[i] = '0' + n;
      return;
    }
  }
}


x86 assembly (clang, -O0):
<os_set_filenumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <os_set_filenumber+0x37>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11c6 <os_set_filenumber+0x96>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11b3 <os_set_filenumber+0x83>
mov    -0x10(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11c6 <os_set_filenumber+0x96>
jmp    11b8 <os_set_filenumber+0x88>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <os_set_filenumber+0x46>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_set_filenumber>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbp
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %rbp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    1181 <os_set_filenumber+0x51>
movsbl -0x1(%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
add    $0xffffffffffffffff,%rbp
test   %rax,%rax
je     1160 <os_set_filenumber+0x30>
mov    %ebp,%eax
add    $0x30,%r14b
mov    %r14b,(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @os_set_filenumber(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* %0, i8* %4
%7 = tail call i32 @strlen(i8* %6)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %14, %3
%10 = phi i64 [ %11, %14 ], [ %8, %3 ]
%11 = add nsw i64 %10, -1
%12 = trunc i64 %10 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %6, i64 %11
%16 = load i8, i8* %15
%17 = tail call i64 @isdigit(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %14
%20 = and i64 %11, 4294967295
%21 = getelementptr inbounds i8, i8* %6, i64 %20
%22 = trunc i32 %2 to i8
%23 = add i8 %22, 48
store i8 %23, i8* %21
br label %24
24: ; preds = %9, %19
ret void
}