#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 */
typedef size_t uint32_t;

/* Variables and functions */
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void path_curr(char *path, char *dest) {
  if (!path) {
    dest[0] = '\0';
    return;
  }
  char *delpos = strchr(path, ('.'));
  uint32_t intpos;
  intpos = delpos ? (uint32_t)(delpos - path) : strlen(path);
  strcpy(dest, path);
  dest[intpos] = '\0';
}


x86 assembly (clang, -O0):
<path_curr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <path_curr+0x27>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b6 <path_curr+0x86>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1188 <path_curr+0x58>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1195 <path_curr+0x65>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_curr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1170 <path_curr+0x40>
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1157 <path_curr+0x27>
mov    %rax,%r15
sub    %rbx,%r15
jmp    1162 <path_curr+0x32>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
add    %r15,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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