#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 */
int dup2(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ my_fatal(char *, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void my_dup2(int old_fd, int new_fd) {
  {
    if (!(old_fd >= 0))
      my_fatal("file \"%s\", line %d, assertion \""
               "old_fd>=0"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/pipex_posix.c",
               363);
  };
  {
    if (!(new_fd >= 0))
      my_fatal("file \"%s\", line %d, assertion \""
               "new_fd>=0"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/pipex_posix.c",
               364);
  };
  if (dup2(old_fd, new_fd) == -1)
    my_fatal("my_dup2(): dup2(): %s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<my_dup2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1162 <my_dup2+0x32>
lea    0xeb1(%rip),%rdi
lea    0xedc(%rip),%rsi
mov    $0x16b,%edx
mov    $0x0,%al
call   1040 <my_fatal@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1186 <my_dup2+0x56>
lea    0xf4b(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x16c,%edx
mov    $0x0,%al
call   1040 <my_fatal@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11b9 <my_dup2+0x89>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
movslq %eax,%rsi
lea    0xf3e(%rip),%rdi
mov    $0x0,%al
call   1040 <my_fatal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_dup2>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
test   %edi,%edi
js     1154 <my_dup2+0x24>
test   %ebx,%ebx
js     1172 <my_dup2+0x42>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
je     118e <my_dup2+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea5(%rip),%rdi
lea    0xed0(%rip),%rsi
mov    $0x16b,%edx
xor    %eax,%eax
call   1040 <my_fatal@plt>
test   %ebx,%ebx
jns    113f <my_dup2+0xf>
lea    0xf45(%rip),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x16c,%edx
xor    %eax,%eax
call   1040 <my_fatal@plt>
jmp    113f <my_dup2+0xf>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
movslq %eax,%rsi
lea    0xf4a(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <my_fatal@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"file \22%s\22, line %d, assertion \22old_fd>=0\22 failed\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/pipex_posix.c\00"
@.str.2 = [50 x i8] c"file \22%s\22, line %d, assertion \22new_fd>=0\22 failed\0A\00"
@.str.3 = [23 x i8] c"my_dup2(): dup2(): %s\0A\00"
@errno = global i32 0
define void @my_dup2(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 363)
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 364)
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @dup2(i32 %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %14
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"file \22%s\22, line %d, assertion \22old_fd>=0\22 failed\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/pipex_posix.c\00"
@.str.2 = [50 x i8] c"file \22%s\22, line %d, assertion \22new_fd>=0\22 failed\0A\00"
@.str.3 = [23 x i8] c"my_dup2(): dup2(): %s\0A\00"
@errno = global i32 0
define void @my_dup2(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, -1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 363)
br label %6
6: ; preds = %4, %2
%7 = icmp sgt i32 %1, -1
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 364)
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @dup2(i32 %0, i32 %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 (i8*, i8*, ...) @my_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %13, %10
ret void
}