#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 dup2_postprocess_(const char *realfnname, int ret, int fd, int fd2) {
  const char *cp = NULL;
  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):
<dup2_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)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     119b <dup2_postprocess_+0x6b>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     119b <dup2_postprocess_+0x6b>
mov    -0x10(%rbp),%edi
call   1040 <fdpathdb_find_path@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1187 <dup2_postprocess_+0x57>
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):
<dup2_postprocess_>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
js     115a <dup2_postprocess_+0x2a>
mov    %ecx,%ebx
cmp    %ecx,%edx
je     115a <dup2_postprocess_+0x2a>
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <fdpathdb_find_path@plt>
test   %rax,%rax
je     1162 <dup2_postprocess_+0x32>
mov    %rax,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
jmp    1164 <dup2_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 @dup2_postprocess_(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i8* null, i8** %9
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %4
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i32, i32* %7
%18 = call i8* @fdpathdb_find_path(i32 %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %9
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %9
br label %24
24: ; preds = %21, %16
%25 = load i8*, i8** %5
%26 = load i32, i32* %8
%27 = load i8*, i8** %9
%28 = load i8*, i8** %9
%29 = call i32 @fdpathdb_register_mapped_path(i8* %25, i32 %26, i8* %27, i8* %28)
br label %30
30: ; preds = %24, %12, %4
ret void
}

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