#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 */
scalar_t__ ancil_send_fd(int, int);
scalar_t__ ancil_send_fds(int, int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
void parent_process(int sock) {
  int fds[2] = {1, 2};
  if (ancil_send_fd(sock, 1)) {
    perror("ancil_send_fd");
    exit(1);
  } else {
    printf("Sent fd.\n");
  }
  sleep(1);
  if (ancil_send_fds(sock, fds, 2)) {
    perror("ancil_send_fds");
    exit(1);
  } else {
    printf("Sent two fds.\n");
  }
}


x86 assembly (clang, -O0):
<parent_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <ancil_send_fd@plt>
cmp    $0x0,%rax
je     11a3 <parent_process+0x43>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x2,%edx
call   1040 <ancil_send_fds@plt>
cmp    $0x0,%rax
je     11ea <parent_process+0x8a>
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent_process>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movabs $0x200000001,%rax
mov    %rax,0x8(%rsp)
mov    $0x1,%esi
call   1050 <ancil_send_fd@plt>
test   %rax,%rax
jne    11c3 <parent_process+0x63>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <ancil_send_fds@plt>
test   %rax,%rax
jne    11cc <parent_process+0x6c>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe36(%rip),%rdi
jmp    11d3 <parent_process+0x73>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.parent_process.fds = [2 x i32] [i32 1, i32 2]
@.str = [14 x i8] c"ancil_send_fd\00"
@.str.1 = [10 x i8] c"Sent fd.\0A\00"
@.str.2 = [15 x i8] c"ancil_send_fds\00"
@.str.3 = [15 x i8] c"Sent two fds.\0A\00"
define void @parent_process(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i32]
store i32 %0, i32* %2
%4 = bitcast [2 x i32]* %3 to i8*
%5 = load i32, i32* %2
%6 = call i64 @ancil_send_fd(i32 %5, i32 1)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11
%14 = call i32 @sleep(i32 1)
%15 = load i32, i32* %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%17 = call i64 @ancil_send_fds(i32 %15, i32* %16, i32 2)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"ancil_send_fd\00"
@.str.2 = [15 x i8] c"ancil_send_fds\00"
@str = [9 x i8] c"Sent fd.\00"
@str.4 = [14 x i8] c"Sent two fds.\00"
define void @parent_process(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 8589934593, i64* %2
%4 = tail call i64 @ancil_send_fd(i32 %0, i32 1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @sleep(i32 1)
%12 = bitcast i64* %2 to i32*
%13 = call i64 @ancil_send_fds(i32 %0, i32* %12, i32 2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
ret void
}