#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 atoi(char const *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int parse_file_blk_info(const char *fpath, char *dpath_buf, char *prefix_buf,
                        int *suffix) {
  if (fpath == NULL) {
    printf("fpath is NULL\n");
    return -1;
  }
  const char *p, *q;
  p = fpath + strlen(fpath) - 1;
  while (p != NULL && *p != '_') {
    p--;
  }
  if (p == NULL) {
    printf("invalid file path\n");
    return -1;
  }
  *suffix = atoi(p + 1);
  q = p;
  while (q != NULL && *q != '/') {
    q--;
  }
  if (q == NULL) {
    strncpy(prefix_buf, fpath, fpath - p);
    prefix_buf[p - q - 1] = 0;
    strcpy(dpath_buf, "./");
  } else {
    strncpy(prefix_buf, q + 1, p - q - 1);
    prefix_buf[p - q - 1] = 0;
    strncpy(dpath_buf, fpath, q - fpath + 1);
    dpath_buf[q - fpath + 1] = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_file_blk_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <parse_file_blk_info+0x3b>
lea    0xe86(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <parse_file_blk_info+0x1e5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x41(%rbp)
je     11d0 <parse_file_blk_info+0x80>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11e0 <parse_file_blk_info+0x90>
jmp    11f1 <parse_file_blk_info+0xa1>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    11b0 <parse_file_blk_info+0x60>
cmpq   $0x0,-0x30(%rbp)
jne    1214 <parse_file_blk_info+0xc4>
lea    0xe0c(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <parse_file_blk_info+0x1e5>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x42(%rbp)
je     1251 <parse_file_blk_info+0x101>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x42(%rbp)
mov    -0x42(%rbp),%al
test   $0x1,%al
jne    1261 <parse_file_blk_info+0x111>
jmp    1272 <parse_file_blk_info+0x122>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1231 <parse_file_blk_info+0xe1>
cmpq   $0x0,-0x38(%rbp)
jne    12c3 <parse_file_blk_info+0x173>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1040 <strcpy@plt>
jmp    132e <parse_file_blk_info+0x1de>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_file_blk_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11f9 <parse_file_blk_info+0xb9>
mov    %rcx,%rbx
mov    %rdi,%r13
mov    %rdx,%rbp
mov    %rsi,(%rsp)
call   1050 <strlen@plt>
movslq %eax,%r12
lea    (%r12,%r13,1),%r15
lea    (%r12,%r13,1),%rax
add    $0xffffffffffffffff,%rax
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
cmpb   $0x5f,(%rax,%r14,1)
lea    -0x1(%r14),%r14
jne    1180 <parse_file_blk_info+0x40>
lea    (%r14,%r15,1),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,(%rbx)
mov    $0xfffffffffffffffe,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmpb   $0x2f,(%r15,%r14,1)
lea    -0x1(%r14),%r14
jne    11b0 <parse_file_blk_info+0x70>
lea    (%r15,%r14,1),%rsi
add    $0x2,%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
lea    (%r12,%r14,1),%edx
add    $0x2,%edx
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strncpy@plt>
add    %rbx,%r12
movb   $0x0,0x2(%r14,%r12,1)
xor    %eax,%eax
jmp    120a <parse_file_blk_info+0xca>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"fpath is NULL\0A\00"
@.str.1 = [19 x i8] c"invalid file path\0A\00"
@.str.2 = [3 x i8] c"./\00"
define i32 @parse_file_blk_info(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %122
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
store i8* %22, i8** %10
br label %23
23: ; preds = %33, %16
%24 = load i8*, i8** %10
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %10
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 95
br label %31
31: ; preds = %26, %23
%32 = phi i1 [ false, %23 ], [ %30, %26 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %10
br label %23
36: ; preds = %31
%37 = load i8*, i8** %10
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %122
41: ; preds = %36
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @atoi(i8* %43)
%45 = load i32*, i32** %9
store i32 %44, i32* %45
%46 = load i8*, i8** %10
store i8* %46, i8** %11
br label %47
47: ; preds = %57, %41
%48 = load i8*, i8** %11
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8*, i8** %11
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 47
br label %55
55: ; preds = %50, %47
%56 = phi i1 [ false, %47 ], [ %54, %50 ]
br i1 %56, label %57, label %60
57: ; preds = %55
%58 = load i8*, i8** %11
%59 = getelementptr inbounds i8, i8* %58, i32 -1
store i8* %59, i8** %11
br label %47
60: ; preds = %55
%61 = load i8*, i8** %11
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %83
63: ; preds = %60
%64 = load i8*, i8** %8
%65 = load i8*, i8** %6
%66 = load i8*, i8** %6
%67 = load i8*, i8** %10
%68 = ptrtoint i8* %66 to i64
%69 = ptrtoint i8* %67 to i64
%70 = sub i64 %68, %69
%71 = trunc i64 %70 to i32
%72 = call i32 @strncpy(i8* %64, i8* %65, i32 %71)
%73 = load i8*, i8** %8
%74 = load i8*, i8** %10
%75 = load i8*, i8** %11
%76 = ptrtoint i8* %74 to i64
%77 = ptrtoint i8* %75 to i64
%78 = sub i64 %76, %77
%79 = sub nsw i64 %78, 1
%80 = getelementptr inbounds i8, i8* %73, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %7
%82 = call i32 @strcpy(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %121
83: ; preds = %60
%84 = load i8*, i8** %8
%85 = load i8*, i8** %11
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8*, i8** %10
%88 = load i8*, i8** %11
%89 = ptrtoint i8* %87 to i64
%90 = ptrtoint i8* %88 to i64
%91 = sub i64 %89, %90
%92 = sub nsw i64 %91, 1
%93 = trunc i64 %92 to i32
%94 = call i32 @strncpy(i8* %84, i8* %86, i32 %93)
%95 = load i8*, i8** %8
%96 = load i8*, i8** %10
%97 = load i8*, i8** %11
%98 = ptrtoint i8* %96 to i64
%99 = ptrtoint i8* %97 to i64
%100 = sub i64 %98, %99
%101 = sub nsw i64 %100, 1
%102 = getelementptr inbounds i8, i8* %95, i64 %101
store i8 0, i8* %102
%103 = load i8*, i8** %7
%104 = load i8*, i8** %6
%105 = load i8*, i8** %11
%106 = load i8*, i8** %6
%107 = ptrtoint i8* %105 to i64
%108 = ptrtoint i8* %106 to i64
%109 = sub i64 %107, %108
%110 = add nsw i64 %109, 1
%111 = trunc i64 %110 to i32
%112 = call i32 @strncpy(i8* %103, i8* %104, i32 %111)
%113 = load i8*, i8** %7
%114 = load i8*, i8** %11
%115 = load i8*, i8** %6
%116 = ptrtoint i8* %114 to i64
%117 = ptrtoint i8* %115 to i64
%118 = sub i64 %116, %117
%119 = add nsw i64 %118, 1
%120 = getelementptr inbounds i8, i8* %113, i64 %119
store i8 0, i8* %120
br label %121
121: ; preds = %83, %63
store i32 0, i32* %5
br label %122
122: ; preds = %121, %39, %14
%123 = load i32, i32* %5
ret i32 %123
}

LLVM IR (-O2):
@str = [14 x i8] c"fpath is NULL\00"
define i32 @parse_file_blk_info(i8* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %39
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %0)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
br label %12
12: ; preds = %12, %8
%13 = phi i8* [ %11, %8 ], [ %14, %12 ]
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 95
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = tail call i32 @atoi(i8* %13)
store i32 %18, i32* %3
br label %19
19: ; preds = %19, %17
%20 = phi i8* [ %14, %17 ], [ %23, %19 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
%23 = getelementptr inbounds i8, i8* %20, i64 -1
br i1 %22, label %24, label %19
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %20, i64 1
%26 = ptrtoint i8* %14 to i64
%27 = ptrtoint i8* %20 to i64
%28 = xor i64 %27, -1
%29 = add i64 %28, %26
%30 = trunc i64 %29 to i32
%31 = tail call i32 @strncpy(i8* %2, i8* %25, i32 %30)
%32 = getelementptr inbounds i8, i8* %2, i64 %29
store i8 0, i8* %32
%33 = ptrtoint i8* %0 to i64
%34 = sub i64 %27, %33
%35 = add nsw i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %36)
%38 = getelementptr inbounds i8, i8* %1, i64 %35
store i8 0, i8* %38
br label %39
39: ; preds = %24, %6
%40 = phi i32 [ -1, %6 ], [ 0, %24 ]
ret i32 %40
}