#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*/ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *strdup(char *);
int strlen(char *);
char *strstr(char *, char *);
int main() {
  char *p = strstr("/storage/emulated/legacy/Downloads/ota/update_signed.zip",
                   "/storage/emulated/legacy");
  printf("fist occurence:%s\n", p);
  char *suffix = strdup(p + strlen("/storage/emulated/legacy"));
  char *fix_path = NULL;
  asprintf(&fix_path, "%s%s", "/data/media/0",
           p + strlen("/storage/emulated/legacy"));
  printf("new path:%s\n", fix_path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xea4(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rcx
cltq
add    %rax,%rcx
lea    -0x20(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    0xe87(%rip),%rdx
call   1050 <asprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf17(%rip),%rdi
lea    0xebe(%rip),%r14
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
movq   $0x0,(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
add    %r14,%rcx
lea    0xeef(%rip),%rsi
lea    0xeed(%rip),%rdx
mov    %rsp,%rdi
call   1050 <asprintf@plt>
mov    (%rsp),%rsi
lea    0xee8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [57 x i8] c"/storage/emulated/legacy/Downloads/ota/update_signed.zip\00"
@.str.1 = [25 x i8] c"/storage/emulated/legacy\00"
@.str.2 = [19 x i8] c"fist occurence:%s\0A\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [14 x i8] c"/data/media/0\00"
@.str.5 = [13 x i8] c"new path:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @strstr(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %3
store i8* null, i8** %4
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [57 x i8] c"/storage/emulated/legacy/Downloads/ota/update_signed.zip\00"
@.str.1 = [25 x i8] c"/storage/emulated/legacy\00"
@.str.2 = [19 x i8] c"fist occurence:%s\0A\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [14 x i8] c"/data/media/0\00"
@.str.5 = [13 x i8] c"new path:%s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [57 x i8], [57 x i8]* @.str, i64 0, i64 %6
%8 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %1
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %9)
ret i32 0
}