#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ host_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sendfd(int, char *, scalar_t__, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, client_sockfd;
  int host_port;
  int yes;
  char buffer[1024];
  struct sockaddr_in host_addr, client_addr;
  host_port = 8989;
  if (argc > 1)
    host_port = atoi(argv[1]);
  if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    do {
      fprintf(stderr, "Error: %s:%d: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/"
              "lab2/server/server.c",
              33, "creating a socket");
      exit(0);
    } while (0);
  }
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
    do {
      fprintf(stderr, "Error: %s:%d: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/"
              "lab2/server/server.c",
              37, "setting socket option SO_REUSEADDR");
      exit(0);
    } while (0);
  memset(&(host_addr), '\0', sizeof(host_addr));
  host_addr.sin_family = AF_INET;
  host_addr.sin_port = htons(host_port);
  host_addr.sin_addr.s_addr = 0;
  if (bind(sockfd, (struct sockaddr *)&host_addr, sizeof(struct sockaddr)) ==
      -1)
    do {
      fprintf(stderr, "Error: %s:%d: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/"
              "lab2/server/server.c",
              46, "binding to socket");
      exit(0);
    } while (0);
  if (listen(sockfd, 1000) == -1)
    do {
      fprintf(stderr, "Error: %s:%d: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/"
              "lab2/server/server.c",
              49, "listening on socket");
      exit(0);
    } while (0);
  signal(SIGCHLD, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);
  int pid;
  int fds[2];
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
    do {
      fprintf(stderr, "Error: %s:%d: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/"
              "lab2/server/server.c",
              57, "socketpair");
      exit(0);
    } while (0);
  if ((pid = fork()) == 0) {
    close(fds[1]);
    char pipe_fd_str[32] = {'\0'};
    char *child_name = "./httpd";
    sprintf(pipe_fd_str, "%d", fds[0]);
    char *child_argv[] = {child_name, pipe_fd_str, 0};
    if (1)
      printf("%s\n", pipe_fd_str);
    if (execv(child_name, child_argv) == -1)
      do {
        fprintf(stderr, "Error: %s:%d: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/"
                "heads/master/lab2/server/server.c",
                71, "execve");
        exit(0);
      } while (0);
  }
  close(fds[0]);
  while (1) {
    int size;
    if ((client_sockfd =
             accept(sockfd, (struct sockaddr *)&client_addr, &size)) == -1)
      do {
        fprintf(stderr, "Error: %s:%d: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/"
                "heads/master/lab2/server/server.c",
                79, "accepting client connection");
        exit(0);
      } while (0);
    printf("Parent process client_sockfd = %d\n", client_sockfd);
    char sock_fd_str[32] = {'\0'};
    sprintf(sock_fd_str, "%d", client_sockfd);
    if (1) {
      printf("sending a socket to the client:\n");
    }
    sendfd(fds[1], sock_fd_str, strlen(sock_fd_str) + 1, client_sockfd);
    close(client_sockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x231d,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    126a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12c3 <main+0x93>
jmp    1294 <main+0x64>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
lea    0xd67(%rip),%rdx
mov    $0x21,%ecx
lea    0xdef(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1324 <main+0xf4>
jmp    12f5 <main+0xc5>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
lea    0xd06(%rip),%rdx
mov    $0x25,%ecx
lea    0xda0(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x428(%rbp)
movq   $0x0,-0x430(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13b0 <main+0x180>
jmp    1381 <main+0x151>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
lea    0xc6f(%rip),%rsi
lea    0xc7a(%rip),%rdx
mov    $0x2e,%ecx
lea    0xd37(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x3e8,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13fa <main+0x1ca>
jmp    13cb <main+0x19b>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc25(%rip),%rsi
lea    0xc30(%rip),%rdx
mov    $0x31,%ecx
lea    0xcff(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
mov    0x2bbe(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
mov    0x2ba7(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    0x2ba9(%rip),%rax
mov    (%rax),%edi
mov    0x2b78(%rip),%rax
mov    (%rax),%esi
lea    -0x44c(%rbp),%rcx
xor    %edx,%edx
call   10b0 <socketpair@plt>
cmp    $0x0,%rax
je     1486 <main+0x256>
jmp    1457 <main+0x227>
mov    0x2b5a(%rip),%rax
mov    (%rax),%edi
lea    0xb99(%rip),%rsi
lea    0xba4(%rip),%rdx
mov    $0x39,%ecx
lea    0xc87(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x444(%rbp)
cmp    $0x0,%eax
jne    1572 <main+0x342>
mov    -0x448(%rbp),%edi
call   1080 <close@plt>
lea    -0x470(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    0xc4b(%rip),%rax
mov    %rax,-0x478(%rbp)
lea    -0x470(%rbp),%rdi
mov    -0x44c(%rbp),%edx
lea    0xc38(%rip),%rsi
call   1110 <sprintf@plt>
mov    -0x478(%rbp),%rax
mov    %rax,-0x490(%rbp)
lea    -0x470(%rbp),%rax
mov    %rax,-0x488(%rbp)
movq   $0x0,-0x480(%rbp)
lea    -0x470(%rbp),%rsi
lea    0xaf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x478(%rbp),%rdi
lea    -0x490(%rbp),%rsi
call   1130 <execv@plt>
cmp    $0xffffffff,%eax
jne    156d <main+0x33d>
jmp    153e <main+0x30e>
mov    0x2a73(%rip),%rax
mov    (%rax),%edi
lea    0xab2(%rip),%rsi
lea    0xabd(%rip),%rdx
mov    $0x47,%ecx
lea    0xbb6(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
jmp    1572 <main+0x342>
mov    -0x44c(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x494(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    15d3 <main+0x3a3>
jmp    15a4 <main+0x374>
mov    0x2a0d(%rip),%rax
mov    (%rax),%edi
lea    0xa4c(%rip),%rsi
lea    0xa57(%rip),%rdx
mov    $0x4f,%ecx
lea    0xb57(%rip),%r8
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xb5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x4c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x4c0(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xb0c(%rip),%rsi
call   1110 <sprintf@plt>
lea    0xb49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x448(%rbp),%eax
mov    %eax,-0x4cc(%rbp)
lea    -0x4c0(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
lea    -0x4c0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4cc(%rbp),%edi
mov    -0x4c8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
mov    -0x18(%rbp),%ecx
call   10c0 <sendfd@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    157d <main+0x34d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    $0x231d,%ebp
cmp    $0x2,%edi
jl     1263 <main+0x23>
mov    0x8(%rsi),%rdi
call   1110 <atoi@plt>
mov    %eax,%ebp
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    0x2d3d(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
jne    12aa <main+0x6a>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
lea    0xd79(%rip),%rdx
lea    0xe06(%rip),%r8
mov    $0x21,%ecx
jmp    1586 <main+0x346>
mov    %eax,%ebx
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
mov    0x2cdc(%rip),%rax
mov    (%rax),%edx
lea    0x3c(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12fd <main+0xbd>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
lea    0xd26(%rip),%rdx
lea    0xdc5(%rip),%r8
mov    $0x25,%ecx
jmp    1586 <main+0x346>
lea    0x28(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0x30(%rsp)
movq   $0x0,0x28(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    136e <main+0x12e>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xcaa(%rip),%rsi
lea    0xcb5(%rip),%rdx
lea    0xd77(%rip),%r8
mov    $0x2e,%ecx
jmp    1586 <main+0x346>
mov    %ebx,%edi
mov    $0x3e8,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13a7 <main+0x167>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rsi
lea    0xc7c(%rip),%rdx
lea    0xd50(%rip),%r8
mov    $0x31,%ecx
jmp    1586 <main+0x346>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
mov    0x2c11(%rip),%rbp
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%esi
lea    0x4(%rsp),%rcx
xor    %edx,%edx
call   10c0 <socketpair@plt>
test   %rax,%rax
jne    148a <main+0x24a>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
jne    14b2 <main+0x272>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
mov    0x4(%rsp),%edx
lea    0xcf3(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   1120 <sprintf@plt>
lea    0xcd7(%rip),%r14
mov    %r14,0x10(%rsp)
mov    %rbp,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1140 <execv@plt>
cmp    $0xffffffff,%eax
jne    14b2 <main+0x272>
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
lea    0xb99(%rip),%rdx
lea    0xc97(%rip),%r8
mov    $0x47,%ecx
jmp    1586 <main+0x346>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
lea    0xb66(%rip),%rsi
lea    0xb71(%rip),%rdx
lea    0xc59(%rip),%r8
mov    $0x39,%ecx
jmp    1586 <main+0x346>
mov    0x4(%rsp),%edi
call   1090 <close@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     1563 <main+0x323>
mov    %eax,%ebp
lea    0x40(%rsp),%r13
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
lea    0xc43(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
mov    %r13,%rdi
lea    0xbfd(%rip),%rsi
mov    %ebp,%edx
call   1120 <sprintf@plt>
lea    0xc38(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%r12d
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12d,%edi
mov    %r13,%rsi
mov    %ebp,%ecx
call   10d0 <sendfd@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1100 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    14f0 <main+0x2b0>
mov    0x2a4e(%rip),%rax
mov    (%rax),%edi
lea    0xa8d(%rip),%rsi
lea    0xa98(%rip),%rdx
lea    0xb9d(%rip),%r8
mov    $0x4f,%ecx
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Error: %s:%d: %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/lab2/server/server.c\00"
@.str.2 = [18 x i8] c"creating a socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [35 x i8] c"setting socket option SO_REUSEADDR\00"
@AF_INET = global i32 0
@.str.4 = [18 x i8] c"binding to socket\00"
@.str.5 = [20 x i8] c"listening on socket\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGPIPE = global i32 0
@AF_UNIX = global i32 0
@.str.6 = [11 x i8] c"socketpair\00"
@.str.7 = [8 x i8] c"./httpd\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@.str.10 = [7 x i8] c"execve\00"
@.str.11 = [28 x i8] c"accepting client connection\00"
@.str.12 = [35 x i8] c"Parent process client_sockfd = %d\0A\00"
@.str.13 = [33 x i8] c"sending a socket to the client:\0A\00"
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
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca [2 x i32]
%15 = alloca [32 x i8]
%16 = alloca i8*
%17 = alloca [3 x i8*]
%18 = alloca i32
%19 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8989, i32* %8
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
br label %27
27: ; preds = %22, %2
%28 = load i32, i32* @PF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %27
br label %33
33: ; preds = %32
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %27
%39 = load i32, i32* %6
%40 = load i32, i32* @SOL_SOCKET
%41 = load i32, i32* @SO_REUSEADDR
%42 = call i32 @setsockopt(i32 %39, i32 %40, i32 %41, i32* %9, i32 4)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %38
br label %45
45: ; preds = %44
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; No predecessors!
br label %50
50: ; preds = %49, %38
%51 = call i32 @memset(%struct.sockaddr_in* %11, i8 signext 0, i32 16)
%52 = load i32, i32* @AF_INET
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %52, i32* %53
%54 = load i32, i32* %8
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %55, i32* %56
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
store i64 0, i64* %58
%59 = load i32, i32* %6
%60 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%61 = call i32 @bind(i32 %59, %struct.sockaddr* %60, i32 4)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %69
63: ; preds = %50
br label %64
64: ; preds = %63
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 0)
unreachable
68: ; No predecessors!
br label %69
69: ; preds = %68, %50
%70 = load i32, i32* %6
%71 = call i32 @listen(i32 %70, i32 1000)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %79
73: ; preds = %69
br label %74
74: ; preds = %73
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%77 = call i32 @exit(i32 0)
unreachable
78: ; No predecessors!
br label %79
79: ; preds = %78, %69
%80 = load i32, i32* @SIGCHLD
%81 = load i32, i32* @SIG_IGN
%82 = call i32 @signal(i32 %80, i32 %81)
%83 = load i32, i32* @SIGPIPE
%84 = load i32, i32* @SIG_IGN
%85 = call i32 @signal(i32 %83, i32 %84)
%86 = load i32, i32* @AF_UNIX
%87 = load i32, i32* @SOCK_STREAM
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%89 = call i64 @socketpair(i32 %86, i32 %87, i32 0, i32* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %79
br label %92
92: ; preds = %91
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%95 = call i32 @exit(i32 0)
unreachable
96: ; No predecessors!
br label %97
97: ; preds = %96, %79
%98 = call i32 (...) @fork()
store i32 %98, i32* %13
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %127
100: ; preds = %97
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 1
%102 = load i32, i32* %101
%103 = call i32 @close(i32 %102)
%104 = bitcast [32 x i8]* %15 to i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8** %16
%105 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%106 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%107 = load i32, i32* %106
%108 = call i32 @sprintf(i8* %105, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %107)
%109 = getelementptr inbounds [3 x i8*], [3 x i8*]* %17, i64 0, i64 0
%110 = load i8*, i8** %16
store i8* %110, i8** %109
%111 = getelementptr inbounds i8*, i8** %109, i64 1
%112 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
store i8* %112, i8** %111
%113 = getelementptr inbounds i8*, i8** %111, i64 1
store i8* null, i8** %113
%114 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %114)
%116 = load i8*, i8** %16
%117 = getelementptr inbounds [3 x i8*], [3 x i8*]* %17, i64 0, i64 0
%118 = call i32 @execv(i8* %116, i8** %117)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %126
120: ; preds = %100
br label %121
121: ; preds = %120
%122 = load i32, i32* @stderr
%123 = call i32 @fprintf(i32 %122, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%124 = call i32 @exit(i32 0)
unreachable
125: ; No predecessors!
br label %126
126: ; preds = %125, %100
br label %127
127: ; preds = %126, %97
%128 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%129 = load i32, i32* %128
%130 = call i32 @close(i32 %129)
br label %131
131: ; preds = %127, %142
%132 = load i32, i32* %6
%133 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%134 = call i32 @accept(i32 %132, %struct.sockaddr* %133, i32* %18)
store i32 %134, i32* %7
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %142
136: ; preds = %131
br label %137
137: ; preds = %136
%138 = load i32, i32* @stderr
%139 = call i32 @fprintf(i32 %138, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 79, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0))
%140 = call i32 @exit(i32 0)
unreachable
141: ; No predecessors!
br label %142
142: ; preds = %141, %131
%143 = load i32, i32* %7
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i32 %143)
%145 = bitcast [32 x i8]* %19 to i8*
%146 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%147 = load i32, i32* %7
%148 = call i32 @sprintf(i8* %146, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %147)
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0))
%150 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 1
%151 = load i32, i32* %150
%152 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%153 = getelementptr inbounds [32 x i8], [32 x i8]* %19, i64 0, i64 0
%154 = call i64 @strlen(i8* %153)
%155 = add nsw i64 %154, 1
%156 = load i32, i32* %7
%157 = call i32 @sendfd(i32 %151, i8* %152, i64 %155, i32 %156)
%158 = load i32, i32* %7
%159 = call i32 @close(i32 %158)
br label %131
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Error: %s:%d: %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/insertion/SEED_LAB/refs/heads/master/lab2/server/server.c\00"
@.str.2 = [18 x i8] c"creating a socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [35 x i8] c"setting socket option SO_REUSEADDR\00"
@AF_INET = global i32 0
@.str.4 = [18 x i8] c"binding to socket\00"
@.str.5 = [20 x i8] c"listening on socket\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGPIPE = global i32 0
@AF_UNIX = global i32 0
@.str.6 = [11 x i8] c"socketpair\00"
@.str.7 = [8 x i8] c"./httpd\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.10 = [7 x i8] c"execve\00"
@.str.11 = [28 x i8] c"accepting client connection\00"
@.str.12 = [35 x i8] c"Parent process client_sockfd = %d\0A\00"
@str = [32 x i8] c"sending a socket to the client:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [2 x i32]
%7 = alloca [32 x i8]
%8 = alloca [3 x i8*]
%9 = alloca i32
%10 = alloca [32 x i8]
%11 = bitcast i32* %3 to i8*
%12 = bitcast %struct.sockaddr_in* %4 to i8*
%13 = bitcast %struct.sockaddr_in* %5 to i8*
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %15, %2
%20 = phi i32 [ %18, %15 ], [ 8989, %2 ]
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %19
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_REUSEADDR
%32 = call i32 @setsockopt(i32 %23, i32 %30, i32 %31, i32* %3, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %29
%39 = call i32 @memset(%struct.sockaddr_in* %4, i8 signext 0, i32 16)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %40, i32* %41
%42 = call i32 @htons(i32 %20)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i64 0, i64* %44
%45 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%46 = call i32 @bind(i32 %23, %struct.sockaddr* %45, i32 4)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %38
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %38
%53 = call i32 @listen(i32 %23, i32 1000)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %52
%60 = load i32, i32* @SIGCHLD
%61 = load i32, i32* @SIG_IGN
%62 = call i32 @signal(i32 %60, i32 %61)
%63 = load i32, i32* @SIGPIPE
%64 = load i32, i32* @SIG_IGN
%65 = call i32 @signal(i32 %63, i32 %64)
%66 = bitcast [2 x i32]* %6 to i8*
%67 = load i32, i32* @AF_UNIX
%68 = load i32, i32* @SOCK_STREAM
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%70 = call i64 @socketpair(i32 %67, i32 %68, i32 0, i32* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %59
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
76: ; preds = %59
%77 = call i32 (...) @fork()
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %98
79: ; preds = %76
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%81 = load i32, i32* %80
%82 = call i32 @close(i32 %81)
%83 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%84 = load i32, i32* %69
%85 = call i32 @sprintf(i8* %83, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %84)
%86 = bitcast [3 x i8*]* %8 to i8*
%87 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8** %87
%88 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* %83, i8** %88
%89 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 2
store i8* null, i8** %89
%90 = call i32 @puts(i8* %83)
%91 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8** %87)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %97
93: ; preds = %79
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%96 = call i32 @exit(i32 0)
unreachable
97: ; preds = %79
br label %98
98: ; preds = %97, %76
%99 = load i32, i32* %69
%100 = call i32 @close(i32 %99)
%101 = bitcast i32* %9 to i8*
%102 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%103 = call i32 @accept(i32 %23, %struct.sockaddr* %102, i32* %9)
%104 = icmp eq i32 %103, -1
br i1 %104, label %108, label %105
105: ; preds = %98
%106 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
br label %112
108: ; preds = %112, %98
%109 = load i32, i32* @stderr
%110 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 79, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0))
%111 = call i32 @exit(i32 0)
unreachable
112: ; preds = %105, %112
%113 = phi i32 [ %103, %105 ], [ %122, %112 ]
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i32 %113)
%115 = call i32 @sprintf(i8* %106, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %113)
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%117 = load i32, i32* %107
%118 = call i64 @strlen(i8* %106)
%119 = add nsw i64 %118, 1
%120 = call i32 @sendfd(i32 %117, i8* %106, i64 %119, i32 %113)
%121 = call i32 @close(i32 %113)
%122 = call i32 @accept(i32 %23, %struct.sockaddr* %102, i32* %9)
%123 = icmp eq i32 %122, -1
br i1 %123, label %108, label %112
}