#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *fdpathdb_find_path(int);
int /*<<< orphan*/ fdpathdb_register_mapped_path(char const *, int,
                                                 char const *, char const *);
char *strdup(char const *);
void dup3_postprocess_(const char *realfnname, int ret, int fd, int fd2,
                       int flags) {
  const char *cp = NULL;
  (void)flags;
  if ((ret >= 0) && (fd != fd2)) {
    cp = fdpathdb_find_path(fd);
    if (cp)
      cp = strdup(cp);
    fdpathdb_register_mapped_path(realfnname, fd2, cp, cp);
  }
}


x86 assembly (clang, -O0):
<dup3_postprocess_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     119f <dup3_postprocess_+0x6f>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     119f <dup3_postprocess_+0x6f>
mov    -0x10(%rbp),%edi
call   1040 <fdpathdb_find_path@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118b <dup3_postprocess_+0x5b>
mov    -0x20(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <fdpathdb_register_mapped_path@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup3_postprocess_>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
js     115a <dup3_postprocess_+0x2a>
mov    %ecx,%ebx
cmp    %ecx,%edx
je     115a <dup3_postprocess_+0x2a>
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <fdpathdb_find_path@plt>
test   %rax,%rax
je     1162 <dup3_postprocess_+0x32>
mov    %rax,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
jmp    1164 <dup3_postprocess_+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ecx,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rcx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fdpathdb_register_mapped_path@plt>

LLVM IR (-O0):
define void @dup3_postprocess_(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i8* null, i8** %11
%12 = load i32, i32* %10
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %5
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i32, i32* %8
%21 = call i8* @fdpathdb_find_path(i32 %20)
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %11
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %11
br label %27
27: ; preds = %24, %19
%28 = load i8*, i8** %6
%29 = load i32, i32* %9
%30 = load i8*, i8** %11
%31 = load i8*, i8** %11
%32 = call i32 @fdpathdb_register_mapped_path(i8* %28, i32 %29, i8* %30, i8* %31)
br label %33
33: ; preds = %27, %15, %5
ret void
}

LLVM IR (-O2):
define void @dup3_postprocess_(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %1, 0
%7 = icmp eq i32 %2, %3
%8 = or i1 %6, %7
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = tail call i8* @fdpathdb_find_path(i32 %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i8* @strdup(i8* %10)
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ %13, %12 ], [ null, %9 ]
%16 = tail call i32 @fdpathdb_register_mapped_path(i8* %0, i32 %3, i8* %15, i8* %15)
br label %17
17: ; preds = %14, %5
ret void
}