#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *get_mount_path(char *path, int n) {
  int i;
  char *m_path = NULL;
  m_path = (char *)malloc(sizeof(char) * 256);
  memset(m_path, 0, 256);
  char *new_path = NULL;
  new_path = path;
  for (i = 0; i < n; i++) {
    new_path = strchr(new_path, '/');
    if (new_path == NULL)
      break;
    new_path++;
  }
  if (i > 3)
    strncpy(m_path, path, strlen(path) - strlen(new_path) - 1);
  else
    strcpy(m_path, path);
  printf("mount path is [%s]\n", m_path);
  return m_path;
}


x86 assembly (clang, -O0):
<get_mount_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1204 <get_mount_path+0x94>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <get_mount_path+0x7a>
jmp    1204 <get_mount_path+0x94>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <get_mount_path+0x4c>
cmpl   $0x3,-0x10(%rbp)
jle    1251 <get_mount_path+0xe1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    %rax,%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
jmp    125e <get_mount_path+0xee>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xd97(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mount_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
test   %r12d,%r12d
jle    11d9 <get_mount_path+0x69>
mov    %r14,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e6 <get_mount_path+0x76>
mov    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    11b0 <get_mount_path+0x40>
mov    %r12d,%ebp
cmp    $0x4,%ebp
jae    11ed <get_mount_path+0x7d>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    1214 <get_mount_path+0xa4>
xor    %ebx,%ebx
cmp    $0x4,%ebp
jb     11d9 <get_mount_path+0x69>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
not    %rax
add    %rax,%rbp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
lea    0xde5(%rip),%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"mount path is [%s]\0A\00"
define i8* @get_mount_path(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %6
%8 = call i64 @malloc(i32 256)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 0, i32 256)
store i8* null, i8** %7
%12 = load i8*, i8** %3
store i8* %12, i8** %7
store i32 0, i32* %5
br label %13
13: ; preds = %26, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = call i8* @strchr(i8* %18, i8 signext 47)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
br label %29
23: ; preds = %17
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
br label %26
26: ; preds = %23
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %13
29: ; preds = %22, %13
%30 = load i32, i32* %5
%31 = icmp sgt i32 %30, 3
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = load i8*, i8** %3
%35 = load i8*, i8** %3
%36 = call i64 @strlen(i8* %35)
%37 = load i8*, i8** %7
%38 = call i64 @strlen(i8* %37)
%39 = sub nsw i64 %36, %38
%40 = sub nsw i64 %39, 1
%41 = call i32 @strncpy(i8* %33, i8* %34, i64 %40)
br label %46
42: ; preds = %29
%43 = load i8*, i8** %6
%44 = load i8*, i8** %3
%45 = call i32 @strcpy(i8* %43, i8* %44)
br label %46
46: ; preds = %42, %32
%47 = load i8*, i8** %6
%48 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %6
ret i8* %49
}

LLVM IR (-O2):
@.str = [20 x i8] c"mount path is [%s]\0A\00"
define i8* @get_mount_path(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 256)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 256)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %26
7: ; preds = %2, %12
%8 = phi i8* [ %13, %12 ], [ %0, %2 ]
%9 = phi i32 [ %14, %12 ], [ 0, %2 ]
%10 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %7
16: ; preds = %12, %7
%17 = phi i32 [ %1, %12 ], [ %9, %7 ]
%18 = phi i8* [ %13, %12 ], [ null, %7 ]
%19 = icmp ugt i32 %17, 3
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%22 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%23 = xor i64 %22, -1
%24 = add i64 %21, %23
%25 = tail call i32 @strncpy(i8* %4, i8* %0, i64 %24)
br label %28
26: ; preds = %2, %16
%27 = tail call i32 @strcpy(i8* %4, i8* %0)
br label %28
28: ; preds = %26, %20
%29 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %4)
ret i8* %4
}