void strcmp_test2() {
  char *ret;
  char *buf = "http://algospot.com/%2a";
  char *buf2 = "http://algospot.com/%2a/%2a/test";
  char temp[32];
  char temp2[32];
  printf("--------- [TEST2] ---------\n");
  ret = strchr(buf, '%');
  strlcpy(temp, buf, ret - buf + 1);
  if (ret + 3 == '\0') {
    printf("[1]it's null\n");
  }
  if (strcmp(ret + 3, "\0") == 0) {
    printf("[2]it's null\n");
    strcat(temp, "*");
    printf("%s\n", temp);
  } else {
    printf("found [%s]\n", ret + 3);
    strcat(temp, ret + 3);
    printf("%s\n", temp);
  }
  return;
}


x86 assembly (clang, -O0):
<strcmp_test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
sub    %rax,%rdx
add    $0x1,%rdx
mov    $0x0,%al
call   1060 <strlcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
cmp    $0x0,%rax
jne    11cc <strcmp_test2+0x7c>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
lea    0xea9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    121e <strcmp_test2+0xce>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x40(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1257 <strcmp_test2+0x107>
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
call   1070 <strcat@plt>
lea    -0x40(%rbp),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp_test2>:
push   %rbx
sub    $0x20,%rsp
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rsi
mov    %rsp,%rbx
mov    $0x15,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <strlcpy@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x2a,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"http://algospot.com/%2a\00"
@.str.1 = [33 x i8] c"http://algospot.com/%2a/%2a/test\00"
@.str.2 = [29 x i8] c"--------- [TEST2] ---------\0A\00"
@.str.3 = [14 x i8] c"[1]it's null\0A\00"
@.str.4 = [2 x i8] zeroinitializer
@.str.5 = [14 x i8] c"[2]it's null\0A\00"
@.str.6 = [2 x i8] c"*\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [12 x i8] c"found [%s]\0A\00"
define void @strcmp_test2() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8** %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i8* @strchr(i8* %7, i32 37)
store i8* %8, i8** %1
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = load i8*, i8** %1
%12 = load i8*, i8** %2
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = add nsw i64 %15, 1
%17 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @strlcpy to i32 (i8*, i8*, i64, ...)*)(i8* %9, i8* %10, i64 %16)
%18 = load i8*, i8** %1
%19 = getelementptr inbounds i8, i8* %18, i64 3
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %0
%24 = load i8*, i8** %1
%25 = getelementptr inbounds i8, i8* %24, i64 3
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%31 = call i8* @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %32)
br label %44
34: ; preds = %23
%35 = load i8*, i8** %1
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%39 = load i8*, i8** %1
%40 = getelementptr inbounds i8, i8* %39, i64 3
%41 = call i8* @strcat(i8* %38, i8* %40)
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %34, %28
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"http://algospot.com/%2a\00"
@str = [28 x i8] c"--------- [TEST2] ---------\00"
@str.9 = [13 x i8] c"[2]it's null\00"
define void @strcmp_test2() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%4 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @strlcpy to i32 (i8*, i8*, i64, ...)*)(i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 21)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%6 = call i64 @strlen(i8* %2)
%7 = getelementptr [32 x i8], [32 x i8]* %1, i64 0, i64 %6
%8 = bitcast i8* %7 to i16*
store i16 42, i16* %8
%9 = call i32 @puts(i8* %2)
ret void
}