#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*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *strip_suffix(char *inbuf, char *outbuf, int maxlen) {
  char *endpoint = strrchr(inbuf, '.');
  int cpylen;
  if (endpoint == NULL)
    return NULL;
  cpylen = endpoint - inbuf;
  if (cpylen > maxlen - 1)
    cpylen = maxlen - 1;
  strncpy(outbuf, inbuf, cpylen);
  outbuf[cpylen] = 0;
  return endpoint;
}


x86 assembly (clang, -O0):
<strip_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115d <strip_suffix+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <strip_suffix+0x89>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1185 <strip_suffix+0x65>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_suffix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1168 <strip_suffix+0x48>
mov    %ebx,%eax
sub    %r15d,%eax
lea    -0x1(%r12),%ebp
cmp    %r12d,%eax
cmovl  %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @strip_suffix(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = icmp slt i32 %10, %2
%12 = add nsw i32 %2, -1
%13 = select i1 %11, i32 %10, i32 %12
%14 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %13)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %3, %6
ret i8* %4
}