#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*/ execl(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, ...);
int socket(int, int, int /*<<< orphan*/);
void testSocket() {
  int sock;
  char buffer[100];
  sock = socket(2, 1, 0);
  read(sock, buffer, 100);
  execl(buffer, "filename", 0);
  sock = socket(1, 1, 0);
  read(sock, buffer, 100);
  execl(buffer, "filename", 0);
  sock = socket(2, 1, 0);
  read(sock, &buffer, 100);
  execl(buffer, "filename", 0);
}


x86 assembly (clang, -O0):
<testSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
mov    $0x0,%al
call   1030 <read@plt>
lea    -0x70(%rbp),%rdi
lea    0xe96(%rip),%rsi
xor    %edx,%edx
call   1040 <execl@plt>
mov    $0x1,%esi
xor    %edx,%edx
mov    %esi,%edi
call   1050 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
mov    $0x0,%al
call   1030 <read@plt>
lea    -0x70(%rbp),%rdi
lea    0xe60(%rip),%rsi
xor    %edx,%edx
call   1040 <execl@plt>
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
mov    $0x0,%al
call   1030 <read@plt>
lea    -0x70(%rbp),%rdi
lea    0xe27(%rip),%rsi
xor    %edx,%edx
call   1040 <execl@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testSocket>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %eax,%eax
call   1030 <read@plt>
lea    0xe9d(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <execl@plt>
mov    $0x1,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <execl@plt>
mov    $0x2,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <execl@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"filename\00"
define void @testSocket() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = call i32 @socket(i32 2, i32 1, i32 0)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 (i32, ...) @read(i32 %4, i8* %5, i32 100)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @execl(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = call i32 @socket(i32 1, i32 1, i32 0)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = call i32 (i32, ...) @read(i32 %10, i8* %11, i32 100)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = call i32 @execl(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%15 = call i32 @socket(i32 2, i32 1, i32 0)
store i32 %15, i32* %1
%16 = load i32, i32* %1
%17 = call i32 (i32, ...) @read(i32 %16, [100 x i8]* %2, i32 100)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%19 = call i32 @execl(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"filename\00"
define void @testSocket() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @socket(i32 2, i32 1, i32 0)
%4 = call i32 (i32, ...) @read(i32 %3, i8* %2, i32 100)
%5 = call i32 @execl(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = call i32 @socket(i32 1, i32 1, i32 0)
%7 = call i32 (i32, ...) @read(i32 %6, i8* %2, i32 100)
%8 = call i32 @execl(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = call i32 @socket(i32 2, i32 1, i32 0)
%10 = call i32 (i32, ...) @read(i32 %9, [100 x i8]* %1, i32 100)
%11 = call i32 @execl(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0)
ret void
}