#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*/ _splitpath(char *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int GetFileName(char *pszFilePath, char *pszFileName, int nBuffSize) {
  char szFname[256] = {0};
  char szExt[256] = {0};
  if (pszFilePath == NULL || pszFileName == NULL || nBuffSize <= 0) {
    return 0;
  }
  _splitpath(pszFilePath, NULL, NULL, szFname, szExt);
  strncpy(pszFileName, szFname, nBuffSize);
  if (strlen(pszFileName) < nBuffSize) {
    strncat(pszFileName, szExt, (strlen(pszFileName) - nBuffSize));
  }
  return 1;
}


x86 assembly (clang, -O0):
<GetFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ac <GetFileName+0x5c>
cmpq   $0x0,-0x18(%rbp)
je     11ac <GetFileName+0x5c>
cmpl   $0x0,-0x1c(%rbp)
jg     11b8 <GetFileName+0x68>
movl   $0x0,-0x4(%rbp)
jmp    123c <GetFileName+0xec>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rcx
lea    -0x220(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1070 <_splitpath@plt>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jge    1235 <GetFileName+0xe5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x230(%rbp),%rdi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
sub    -0x1c(%rbp),%edx
call   1060 <strncat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFileName>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
test   %rdi,%rdi
je     129a <GetFileName+0x15a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     129a <GetFileName+0x15a>
mov    %edx,%r14d
test   %edx,%edx
jle    129a <GetFileName+0x15a>
lea    0x100(%rsp),%rbp
mov    %rsp,%r8
xor    %esi,%esi
xor    %edx,%edx
mov    %rbp,%rcx
call   1060 <_splitpath@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebp
cmp    %r14d,%eax
jge    129a <GetFileName+0x15a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %r14d,%eax
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <strncat@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetFileName(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = bitcast [256 x i8]* %8 to i8*
%11 = bitcast [256 x i8]* %9 to i8*
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %7
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %14, %3
store i32 0, i32* %4
br label %43
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 @_splitpath(i8* %22, i32* null, i32* null, i8* %23, i8* %24)
%26 = load i8*, i8** %6
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %7
%29 = call i32 @strncpy(i8* %26, i8* %27, i32 %28)
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %21
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = load i32, i32* %7
%40 = sub nsw i32 %38, %39
%41 = call i32 @strncat(i8* %35, i8* %36, i32 %40)
br label %42
42: ; preds = %34, %21
store i32 1, i32* %4
br label %43
43: ; preds = %42, %20
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @GetFileName(i8* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %0, null
%9 = icmp eq i8* %1, null
%10 = or i1 %8, %9
%11 = icmp slt i32 %2, 1
%12 = or i1 %10, %11
br i1 %12, label %22, label %13
13: ; preds = %3
%14 = call i32 @_splitpath(i8* %0, i32* null, i32* null, i8* %6, i8* %7)
%15 = call i32 @strncpy(i8* %1, i8* %6, i32 %2)
%16 = call i32 @strlen(i8* %1)
%17 = icmp slt i32 %16, %2
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 @strlen(i8* %1)
%20 = sub nsw i32 %19, %2
%21 = call i32 @strncat(i8* %1, i8* %7, i32 %20)
br label %22
22: ; preds = %13, %18, %3
%23 = phi i32 [ 0, %3 ], [ 1, %18 ], [ 1, %13 ]
ret i32 %23
}