int main() {
  const char *names[] = {
      "/home/user1/tmp/coverage/test",
      "/home/user1/tmp/covert/operator",
      "/home/user1/tmp/coven/members",
  };
  int len = common_len(names, sizeof(names) / sizeof(const char *), '/');
  if (!len)
    printf("No common path\n");
  else
    printf("Common path: %.*s\n", len, names[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2cca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cc7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2cc4(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x3,%esi
mov    $0x2f,%edx
mov    $0x0,%al
call   1040 <common_len@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1185 <main+0x65>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119a <main+0x7a>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2cd5(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2cb9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x3,%esi
mov    $0x2f,%edx
xor    %eax,%eax
call   1050 <common_len@plt>
test   %eax,%eax
je     1179 <main+0x49>
mov    (%rsp),%rdx
lea    0xeee(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1185 <main+0x55>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/home/user1/tmp/coverage/test\00"
@.str.1 = [32 x i8] c"/home/user1/tmp/covert/operator\00"
@.str.2 = [30 x i8] c"/home/user1/tmp/coven/members\00"
@__const.main.names = [3 x i8*] [i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [16 x i8] c"No common path\0A\00"
@.str.4 = [19 x i8] c"Common path: %.*s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [3 x i8*]* %2 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%6 = call i32 (i8**, i64, i32, ...) bitcast (i32 (...)* @common_len to i32 (i8**, i64, i32, ...)*)(i8** %5, i64 3, i32 47)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %16
11: ; preds = %0
%12 = load i32, i32* %3
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %12, i8* %14)
br label %16
16: ; preds = %11, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"/home/user1/tmp/coverage/test\00"
@.str.1 = [32 x i8] c"/home/user1/tmp/covert/operator\00"
@.str.2 = [30 x i8] c"/home/user1/tmp/coven/members\00"
@__const.main.names = [3 x i8*] [i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i32 0, i32 0)]
@.str.4 = [19 x i8] c"Common path: %.*s\0A\00"
@str = [15 x i8] c"No common path\00"
define i32 @main() {
%1 = alloca [3 x i8*]
%2 = bitcast [3 x i8*]* %1 to i8*
%3 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
%4 = call i32 (i8**, i64, i32, ...) bitcast (i32 (...)* @common_len to i32 (i8**, i64, i32, ...)*)(i8** %3, i64 3, i32 47)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %4, i8* %9)
br label %11
11: ; preds = %8, %6
ret i32 0
}