int test(input, result) const char *input;
const char *result;
{
  int retval;
  char *cp;
  cp = strdupa(input);
  cp = dirname(cp);
  retval = strcmp(cp, result);
  if (retval)
    printf("dirname(\"%s\") should be \"%s\", but is \"%s\"\n", input, result,
           cp);
  return retval;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1060 <strdupa@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <dirname@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a6 <test+0x66>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <strdupa@plt>
movslq %eax,%rdi
xor    %eax,%eax
call   1040 <dirname@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1189 <test+0x49>
lea    0xe87(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"dirname(\22%s\22) should be \22%s\22, but is \22%s\22\0A\00"
define i32 @test(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @strdupa to i32 (i8*, ...)*)(i8* %7)
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @dirname to i32 (i8*, ...)*)(i8* %11)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i8*, i8** %4
%17 = call i32 @strcmp(i8* %15, i8* %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = load i8*, i8** %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
br label %25
25: ; preds = %20, %2
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [43 x i8] c"dirname(\22%s\22) should be \22%s\22, but is \22%s\22\0A\00"
define i32 @test(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @strdupa to i32 (i8*, ...)*)(i8* %0)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dirname to i32 (i8*, ...)*)(i8* %5)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(1) %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %8)
br label %13
13: ; preds = %11, %2
ret i32 %9
}