int test_stat(path, statb) const char *path;
struct stat *statb;
{
  int fd;
  if (strncmp(path, "/dev/fd/", 8) == 0 && getn(path + 8, &fd))
    return fstat(fd, statb);
  return stat(path, statb);
}


x86 assembly (clang, -O0):
<test_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a0 <test_stat+0x60>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1040 <getn@plt>
cmp    $0x0,%eax
je     11a0 <test_stat+0x60>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1060 <fstat@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <test_stat+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <stat@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_stat>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     116e <test_stat+0x2e>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <stat@plt>
jmp    1190 <test_stat+0x50>
lea    0x8(%rbx),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <getn@plt>
test   %eax,%eax
je     115f <test_stat+0x1f>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fstat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type opaque
@.str = [9 x i8] c"/dev/fd/\00"
define i32 @test_stat(i8* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
%7 = load i8*, i8** %4
%8 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 8)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 8
%13 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @getn to i32 (i8*, i32*, ...)*)(i8* %12, i32* %6)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* %6
%17 = load %struct.stat*, %struct.stat** %5
%18 = call i32 (i32, %struct.stat*, ...) bitcast (i32 (...)* @fstat to i32 (i32, %struct.stat*, ...)*)(i32 %16, %struct.stat* %17)
store i32 %18, i32* %3
br label %23
19: ; preds = %10, %2
%20 = load i8*, i8** %4
%21 = load %struct.stat*, %struct.stat** %5
%22 = call i32 (i8*, %struct.stat*, ...) bitcast (i32 (...)* @stat to i32 (i8*, %struct.stat*, ...)*)(i8* %20, %struct.stat* %21)
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type opaque
@.str = [9 x i8] c"/dev/fd/\00"
define i32 @test_stat(i8* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strncmp(i8* dereferenceable(1) %0, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 8)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @getn to i32 (i8*, i32*, ...)*)(i8* %8, i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i32 (i32, %struct.stat*, ...) bitcast (i32 (...)* @fstat to i32 (i32, %struct.stat*, ...)*)(i32 %12, %struct.stat* %1)
br label %16
14: ; preds = %7, %2
%15 = call i32 (i8*, %struct.stat*, ...) bitcast (i32 (...)* @stat to i32 (i8*, %struct.stat*, ...)*)(i8* %0, %struct.stat* %1)
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ %13, %11 ], [ %15, %14 ]
ret i32 %17
}