void printonmatch(ptr, a, rep) char **ptr;
char *a;
char *rep;
{
  int l = strlen(a);
  if (strncmp(*ptr, a, l) == 0) {
    printf("%s", rep);
    *ptr += l;
    if (**ptr)
      printf(",");
  }
}


x86 assembly (clang, -O0):
<printonmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11b5 <printonmatch+0x85>
mov    -0x18(%rbp),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpb   $0x0,(%rax)
je     11b0 <printonmatch+0x80>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b5 <printonmatch+0x85>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printonmatch>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    (%r15),%rdi
movslq %eax,%r12
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
je     117a <printonmatch+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%rax
lea    (%rax,%r12,1),%rcx
mov    %rcx,(%r15)
cmpb   $0x0,(%rax,%r12,1)
je     116e <printonmatch+0x2e>
mov    $0x2c,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c",\00"
define void @printonmatch(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %7
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = call i32 @strncmp(i8* %12, i8* %13, i64 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %7
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %22
%26 = load i8**, i8*** %4
%27 = load i8*, i8** %26
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %18
br label %33
33: ; preds = %32, %3
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @printonmatch(i8** nocapture %0, i8* nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = load i8*, i8** %0
%6 = shl i64 %4, 32
%7 = ashr exact i64 %6, 32
%8 = tail call i32 @strncmp(i8* %5, i8* %1, i64 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = load i8*, i8** %0
%13 = getelementptr inbounds i8, i8* %12, i64 %7
store i8* %13, i8** %0
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = tail call i32 @putchar(i32 44)
br label %18
18: ; preds = %10, %16, %3
ret void
}