#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*/ memcpy(char *, char const *, int);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
const char *pathtok(const char *path, char *tok) {
  int len;
  const char *dot = strchr(path, '.');
  if (!dot) {
    strcpy(tok, path);
    return 0;
  }
  len = dot - path;
  memcpy(tok, path, len);
  tok[len] = 0;
  return dot + 1;
}


x86 assembly (clang, -O0):
<pathtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1177 <pathtok+0x47>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ad <pathtok+0x7d>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathtok>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1172 <pathtok+0x42>
mov    %rax,%rbx
mov    %rax,%r12
sub    %r15,%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x1,%rbx
jmp    117f <pathtok+0x4f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @pathtok(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %17
7: ; preds = %2
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %11)
%13 = shl i64 %10, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %3, i64 1
br label %17
17: ; preds = %7, %5
%18 = phi i8* [ %16, %7 ], [ null, %5 ]
ret i8* %18
}