#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*/ connect(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ socket(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
void dummy() {
  char *arg[] = {NULL};
  socket(0, 0, 0);
  connect(0, NULL, 0);
  fork();
  dup2(0, 0);
  execv("", arg);
  perror("");
  exit(0);
}


x86 assembly (clang, -O0):
<dummy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   10a0 <socket@plt>
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%esi
mov    %edx,%edi
call   1070 <connect@plt>
mov    $0x0,%al
call   1090 <fork@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <dup2@plt>
lea    -0x8(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1080 <execv@plt>
lea    0xe29(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<dummy>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <socket@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <connect@plt>
xor    %eax,%eax
call   1080 <fork@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xe55(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <execv@plt>
mov    %rbx,%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @dummy() {
%1 = alloca [1 x i8*]
%2 = bitcast [1 x i8*]* %1 to i8*
%3 = call i32 @socket(i32 0, i32 0, i32 0)
%4 = call i32 @connect(i32 0, i32* null, i32 0)
%5 = call i32 (...) @fork()
%6 = call i32 @dup2(i32 0, i32 0)
%7 = getelementptr inbounds [1 x i8*], [1 x i8*]* %1, i64 0, i64 0
%8 = call i32 @execv(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7)
%9 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @dummy() {
%1 = alloca [1 x i8*]
%2 = bitcast [1 x i8*]* %1 to i8*
%3 = bitcast [1 x i8*]* %1 to i64*
store i64 0, i64* %3
%4 = tail call i32 @socket(i32 0, i32 0, i32 0)
%5 = tail call i32 @connect(i32 0, i32* null, i32 0)
%6 = tail call i32 (...) @fork()
%7 = tail call i32 @dup2(i32 0, i32 0)
%8 = getelementptr inbounds [1 x i8*], [1 x i8*]* %1, i64 0, i64 0
%9 = call i32 @execv(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8)
%10 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
}