#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 */
struct rlimit {
  scalar_t__ rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ F_DUPFD;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ RLIMIT_NOFILE;
int dup(int);
int dup2(int, int);
int /*<<< orphan*/ err(int, char *);
int fcntl(int, int /*<<< orphan*/, int);
int getafile();
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct rlimit rlp;
  int orgfd, fd1, fd2, test = 0;
  orgfd = getafile();
  printf("1..17\n");
  if ((fd1 = dup(orgfd)) < 0)
    err(1, "dup");
  printf("ok %d - dup(2) works\n", ++test);
  if (fcntl(fd1, F_SETFD, 1) != 0)
    err(1, "fcntl(F_SETFD)");
  if ((fd2 = dup2(fd1, fd1 + 1)) < 0)
    err(1, "dup2");
  printf("ok %d - dup2(2) works\n", ++test);
  ++test;
  if (fd2 != fd1 + 1)
    printf("no ok %d - dup2(2) didn't give us the right fd\n", test);
  else
    printf("ok %d - dup2(2) returned a correct fd\n", test);
  if ((fd2 = dup2(fd1, fd1)) < 0)
    err(1, "dup2");
  printf("ok %d - dup2(2) to itself works\n", ++test);
  ++test;
  if (fd2 != fd1)
    printf("not ok %d - dup2(2) didn't give us the right fd\n", test);
  else
    printf("ok %d - dup2(2) to itself returned a correct fd\n", test);
  if ((fd2 = fcntl(fd1, F_DUPFD, 0)) < 0)
    err(1, "fcntl(F_DUPFD)");
  printf("ok %d - fcntl(F_DUPFD) works\n", ++test);
  ++test;
  if (getrlimit(RLIMIT_NOFILE, &rlp) < 0)
    err(1, "getrlimit");
  if ((fd2 = dup2(fd1, (int)(rlp.rlim_cur + 1))) >= 0)
    printf("not ok %d - dup2(2) bypassed NOFILE limit\n", test);
  else
    printf("ok %d - dup2(2) didn't bypass NOFILE limit\n", test);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1070 <getafile@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <dup@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11ca <main+0x5a>
mov    $0x1,%edi
lea    0xe42(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
je     1211 <main+0xa1>
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
call   1080 <err@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
call   1040 <dup2@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    123c <main+0xcc>
mov    $0x1,%edi
lea    0xdf9(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1283 <main+0x113>
mov    -0x28(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1294 <main+0x124>
mov    -0x28(%rbp),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <dup2@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    12bc <main+0x14c>
mov    $0x1,%edi
lea    0xd79(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     12fe <main+0x18e>
mov    -0x28(%rbp),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    130f <main+0x19f>
mov    -0x28(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    133f <main+0x1cf>
mov    $0x1,%edi
lea    0xdec(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1090 <getrlimit@plt>
cmp    $0x0,%rax
jge    138c <main+0x21c>
mov    $0x1,%edi
lea    0xdcc(%rip),%rsi
call   1080 <err@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,%esi
call   1040 <dup2@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jl     13c0 <main+0x250>
mov    -0x28(%rbp),%esi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13d1 <main+0x261>
mov    -0x28(%rbp),%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <getafile@plt>
mov    %eax,%ebx
lea    0x1015(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <dup@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11bc <main+0x3c>
lea    0xe4e(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0xe41(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
je     11fa <main+0x7a>
lea    0xe2a(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0x1(%r14),%ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <dup2@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    121f <main+0x9f>
lea    0xe14(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0xe08(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %ebp,%ebx
lea    0xe3a(%rip),%rax
lea    0xe03(%rip),%rdi
cmove  %rax,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %r14d,%esi
call   1050 <dup2@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1274 <main+0xf4>
lea    0xdbf(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0xe21(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r14d,%ebx
lea    0xe5d(%rip),%rax
lea    0xe25(%rip),%rdi
cmove  %rax,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
jns    12d0 <main+0x150>
lea    0xe59(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0xe57(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   10a0 <getrlimit@plt>
test   %rax,%rax
jns    130c <main+0x18c>
lea    0xe4a(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x8(%rsp),%esi
add    $0x1,%esi
mov    %r14d,%edi
call   1050 <dup2@plt>
test   %eax,%eax
lea    0xe32(%rip),%rax
lea    0xe56(%rip),%rdi
cmovns %rax,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64 }
@.str = [7 x i8] c"1..17\0A\00"
@.str.1 = [4 x i8] c"dup\00"
@.str.2 = [22 x i8] c"ok %d - dup(2) works\0A\00"
@F_SETFD = global i32 0
@.str.3 = [15 x i8] c"fcntl(F_SETFD)\00"
@.str.4 = [5 x i8] c"dup2\00"
@.str.5 = [23 x i8] c"ok %d - dup2(2) works\0A\00"
@.str.6 = [48 x i8] c"no ok %d - dup2(2) didn't give us the right fd\0A\00"
@.str.7 = [39 x i8] c"ok %d - dup2(2) returned a correct fd\0A\00"
@.str.8 = [33 x i8] c"ok %d - dup2(2) to itself works\0A\00"
@.str.9 = [49 x i8] c"not ok %d - dup2(2) didn't give us the right fd\0A\00"
@.str.10 = [49 x i8] c"ok %d - dup2(2) to itself returned a correct fd\0A\00"
@F_DUPFD = global i32 0
@.str.11 = [15 x i8] c"fcntl(F_DUPFD)\00"
@.str.12 = [30 x i8] c"ok %d - fcntl(F_DUPFD) works\0A\00"
@RLIMIT_NOFILE = global i32 0
@.str.13 = [10 x i8] c"getrlimit\00"
@.str.14 = [43 x i8] c"not ok %d - dup2(2) bypassed NOFILE limit\0A\00"
@.str.15 = [44 x i8] c"ok %d - dup2(2) didn't bypass NOFILE limit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = call i32 (...) @getafile()
store i32 %11, i32* %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %7
%14 = call i32 @dup(i32 %13)
store i32 %14, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i32, i32* %10
%20 = add nsw i32 %19, 1
store i32 %20, i32* %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = load i32, i32* @F_SETFD
%24 = call i32 @fcntl(i32 %22, i32 %23, i32 1)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %18
%29 = load i32, i32* %8
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = call i32 @dup2(i32 %29, i32 %31)
store i32 %32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
%42 = load i32, i32* %9
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %49
46: ; preds = %36
%47 = load i32, i32* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %47)
br label %52
49: ; preds = %36
%50 = load i32, i32* %10
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %8
%54 = load i32, i32* %8
%55 = call i32 @dup2(i32 %53, i32 %54)
store i32 %55, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %52
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
%65 = load i32, i32* %9
%66 = load i32, i32* %8
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %59
%69 = load i32, i32* %10
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), i32 %69)
br label %74
71: ; preds = %59
%72 = load i32, i32* %10
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %71, %68
%75 = load i32, i32* %8
%76 = load i32, i32* @F_DUPFD
%77 = call i32 @fcntl(i32 %75, i32 %76, i32 0)
store i32 %77, i32* %9
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %81
81: ; preds = %79, %74
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
%87 = load i32, i32* @RLIMIT_NOFILE
%88 = call i64 @getrlimit(i32 %87, %struct.rlimit* %6)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %81
%91 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
br label %92
92: ; preds = %90, %81
%93 = load i32, i32* %8
%94 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%95 = load i64, i64* %94
%96 = add nsw i64 %95, 1
%97 = trunc i64 %96 to i32
%98 = call i32 @dup2(i32 %93, i32 %97)
store i32 %98, i32* %9
%99 = icmp sge i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %92
%101 = load i32, i32* %10
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.14, i64 0, i64 0), i32 %101)
br label %106
103: ; preds = %92
%104 = load i32, i32* %10
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0), i32 %104)
br label %106
106: ; preds = %103, %100
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
@.str.1 = [4 x i8] c"dup\00"
@.str.2 = [22 x i8] c"ok %d - dup(2) works\0A\00"
@F_SETFD = global i32 0
@.str.3 = [15 x i8] c"fcntl(F_SETFD)\00"
@.str.4 = [5 x i8] c"dup2\00"
@.str.5 = [23 x i8] c"ok %d - dup2(2) works\0A\00"
@.str.6 = [48 x i8] c"no ok %d - dup2(2) didn't give us the right fd\0A\00"
@.str.7 = [39 x i8] c"ok %d - dup2(2) returned a correct fd\0A\00"
@.str.8 = [33 x i8] c"ok %d - dup2(2) to itself works\0A\00"
@.str.9 = [49 x i8] c"not ok %d - dup2(2) didn't give us the right fd\0A\00"
@.str.10 = [49 x i8] c"ok %d - dup2(2) to itself returned a correct fd\0A\00"
@F_DUPFD = global i32 0
@.str.11 = [15 x i8] c"fcntl(F_DUPFD)\00"
@.str.12 = [30 x i8] c"ok %d - fcntl(F_DUPFD) works\0A\00"
@RLIMIT_NOFILE = global i32 0
@.str.13 = [10 x i8] c"getrlimit\00"
@.str.14 = [43 x i8] c"not ok %d - dup2(2) bypassed NOFILE limit\0A\00"
@.str.15 = [44 x i8] c"ok %d - dup2(2) didn't bypass NOFILE limit\0A\00"
@str = [6 x i8] c"1..17\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = tail call i32 (...) @getafile()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @dup(i32 %5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = load i32, i32* @F_SETFD
%14 = tail call i32 @fcntl(i32 %7, i32 %13, i32 1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = add nsw i32 %7, 1
%20 = tail call i32 @dup2(i32 %7, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 2)
%26 = icmp eq i32 %20, %19
%27 = select i1 %26, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %27, i32 3)
%29 = tail call i32 @dup2(i32 %7, i32 %7)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %24
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 4)
%35 = icmp eq i32 %29, %7
%36 = select i1 %35, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %36, i32 5)
%38 = load i32, i32* @F_DUPFD
%39 = tail call i32 @fcntl(i32 %7, i32 %38, i32 0)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %43
43: ; preds = %41, %33
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 6)
%45 = load i32, i32* @RLIMIT_NOFILE
%46 = call i64 @getrlimit(i32 %45, %struct.rlimit* %3)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
br label %50
50: ; preds = %48, %43
%51 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i32
%54 = add i32 %53, 1
%55 = call i32 @dup2(i32 %7, i32 %54)
%56 = icmp sgt i32 %55, -1
%57 = select i1 %56, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %57, i32 7)
ret i32 0
}