#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int open(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int s1;
  int s2;
  {
    int i;
    for (i = 3; i < 64; i++)
      close(i);
  };
  s1 = open("/dev/null", O_RDONLY);
  s2 = open("/dev/null", O_RDONLY);
  dup2(s1, 20);
  dup2(s1, s2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x1c(%rbp)
cmpl   $0x40,-0x1c(%rbp)
jge    116d <main+0x3d>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <main+0x1d>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x14,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <dup2@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x3,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x1,%ebx
cmp    $0x40,%ebx
jne    1140 <main+0x10>
mov    0x2e92(%rip),%r14
mov    (%r14),%esi
lea    0xea0(%rip),%rbx
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x14,%esi
call   1030 <dup2@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <dup2@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %8
br label %9
9: ; preds = %15, %2
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 64
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %8
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %12
%16 = load i32, i32* %8
%17 = add nsw i32 %16, 1
store i32 %17, i32* %8
br label %9
18: ; preds = %9
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @dup2(i32 %23, i32 20)
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i32 @dup2(i32 %25, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 3, %2 ], [ %6, %3 ]
%5 = tail call i32 @close(i32 %4)
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 64
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @dup2(i32 %10, i32 20)
%14 = tail call i32 @dup2(i32 %10, i32 %12)
ret i32 0
}