#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 */
typedef int uid_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ addr_buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
unsigned int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getresuid(int *, int *, int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned int);
char *inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int listenfd, connfd;
  struct sockaddr_in client_addr, server_addr;
  socklen_t client_addr_len, server_addr_len;
  char addr_buff[256];
  unsigned int port_number;
  uid_t ruid, euid, suid;
  if (argc != 2) {
    fprintf(stderr, "Invocation: %s <PORT>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  port_number = atoi(argv[1]);
  listenfd = socket(PF_INET, SOCK_STREAM, 0);
  if (listenfd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(port_number);
  server_addr_len = sizeof(server_addr);
  if (getresuid(&ruid, &euid, &suid) == -1) {
    perror("getresgid()");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "UID: %u, EUID: %u, SUID: %u\n", ruid, euid, suid);
  fprintf(stdout, "Binding to port %u...\n", port_number);
  if (bind(listenfd, (struct sockaddr *)&server_addr, server_addr_len) == -1) {
    perror("bind()");
    exit(EXIT_FAILURE);
  }
  if (getresuid(&ruid, &euid, &suid) == -1) {
    perror("getresgid()");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "UID: %u, EUID: %u, SUID: %u\n", ruid, euid, suid);
  if (euid == 0 || suid == 0) {
    fprintf(stderr, "Run server as unprivileged user!\n");
    exit(EXIT_FAILURE);
  }
  if (listen(listenfd, 2) == -1) {
    perror("listen()");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Server is listening for incoming connection...\n");
  client_addr_len = sizeof(client_addr);
  connfd = accept(listenfd, (struct sockaddr *)&client_addr, &client_addr_len);
  if (connfd == -1) {
    perror("accept()");
    exit(EXIT_FAILURE);
  }
  fprintf(
      stdout, "TCP connection accepted from %s:%d\n",
      inet_ntop(AF_INET, &client_addr.sin_addr, addr_buff, sizeof(addr_buff)),
      ntohs(client_addr.sin_port));
  sleep(5);
  fprintf(stdout, "Closing connected socket (sending FIN to client)...\n");
  close(connfd);
  close(listenfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     124f <main+0x4f>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x144(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12a2 <main+0xa2>
lea    0xd88(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x144(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
movl   $0xc,-0x40(%rbp)
lea    -0x148(%rbp),%rdi
lea    -0x14c(%rbp),%rsi
lea    -0x150(%rbp),%rdx
call   1090 <getresuid@plt>
cmp    $0xffffffff,%eax
jne    1321 <main+0x121>
lea    0xd12(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
mov    -0x148(%rbp),%edx
mov    -0x14c(%rbp),%ecx
mov    -0x150(%rbp),%r8d
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
mov    -0x144(%rbp),%edx
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    139a <main+0x19a>
lea    0xcd9(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x148(%rbp),%rdi
lea    -0x14c(%rbp),%rsi
lea    -0x150(%rbp),%rdx
call   1090 <getresuid@plt>
cmp    $0xffffffff,%eax
jne    13d7 <main+0x1d7>
lea    0xc5c(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
mov    -0x148(%rbp),%edx
mov    -0x14c(%rbp),%ecx
mov    -0x150(%rbp),%r8d
lea    0xc32(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmpl   $0x0,-0x14c(%rbp)
je     141b <main+0x21b>
cmpl   $0x0,-0x150(%rbp)
jne    1440 <main+0x240>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
lea    0xc3c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1470 <main+0x270>
lea    0xc2c(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
lea    0xc12(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    14c5 <main+0x2c5>
lea    0xc10(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2afa(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2ae4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x15c(%rbp)
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
lea    -0x140(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x158(%rbp)
mov    -0x28(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rdx
mov    %eax,%ecx
lea    0xbb0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   1110 <sleep@plt>
mov    0x2a7d(%rip),%rax
mov    (%rax),%edi
lea    0xbb3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2a4e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
cmp    $0x2,%edi
jne    1249 <main+0x49>
mov    0x8(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0x68>
lea    0xdd3(%rip),%rdi
jmp    1333 <main+0x133>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xda4(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1338 <main+0x138>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d66(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <getresuid@plt>
cmp    $0xffffffff,%eax
je     132c <main+0x12c>
mov    0x2cec(%rip),%r12
mov    (%r12),%edi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    (%rsp),%r8d
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xd5c(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1315 <main+0x115>
lea    0xd4d(%rip),%rdi
jmp    1333 <main+0x133>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <getresuid@plt>
cmp    $0xffffffff,%eax
jne    1346 <main+0x146>
lea    0xced(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    (%r12),%edi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    (%rsp),%r8d
lea    0xccf(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
cmpl   $0x0,0x4(%rsp)
je     138b <main+0x18b>
cmpl   $0x0,(%rsp)
je     138b <main+0x18b>
mov    %ebx,%edi
mov    $0x2,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13a4 <main+0x1a4>
lea    0xd00(%rip),%rdi
jmp    1333 <main+0x133>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
lea    0xccc(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1338 <main+0x138>
mov    (%r12),%edi
lea    0xce3(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1e0>
lea    0xce7(%rip),%rdi
jmp    1333 <main+0x133>
mov    %eax,%ebp
mov    (%r12),%r14d
mov    (%r15),%edi
lea    0x24(%rsp),%rsi
lea    0x30(%rsp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%r15
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xcbb(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   1110 <sleep@plt>
mov    (%r12),%edi
lea    0xcbb(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Invocation: %s <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [12 x i8] c"getresgid()\00"
@stdout = global i32 0
@.str.3 = [29 x i8] c"UID: %u, EUID: %u, SUID: %u\0A\00"
@.str.4 = [23 x i8] c"Binding to port %u...\0A\00"
@.str.5 = [7 x i8] c"bind()\00"
@.str.6 = [34 x i8] c"Run server as unprivileged user!\0A\00"
@.str.7 = [9 x i8] c"listen()\00"
@.str.8 = [48 x i8] c"Server is listening for incoming connection...\0A\00"
@.str.9 = [9 x i8] c"accept()\00"
@.str.10 = [36 x i8] c"TCP connection accepted from %s:%d\0A\00"
@.str.11 = [53 x i8] c"Closing connected socket (sending FIN to client)...\0A\00"
@EXIT_SUCCESS = 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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %13
%32 = load i32, i32* @PF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %27
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %27
%42 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%43 = load i32, i32* @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %43, i32* %44
%45 = load i32, i32* @INADDR_ANY
%46 = call i32 @htonl(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
store i32 %46, i32* %48
%49 = load i32, i32* %13
%50 = call i32 @htons(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %50, i32* %51
store i32 12, i32* %11
%52 = call i32 @getresuid(i32* %14, i32* %15, i32* %16)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %41
%55 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %41
%59 = load i32, i32* @stdout
%60 = load i32, i32* %14
%61 = load i32, i32* %15
%62 = load i32, i32* %16
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %60, i32 %61, i32 %62)
%64 = load i32, i32* @stdout
%65 = load i32, i32* %13
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %6
%68 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%69 = load i32, i32* %11
%70 = call i32 @bind(i32 %67, %struct.sockaddr* %68, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %76
72: ; preds = %58
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %58
%77 = call i32 @getresuid(i32* %14, i32* %15, i32* %16)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %76
%80 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %76
%84 = load i32, i32* @stdout
%85 = load i32, i32* %14
%86 = load i32, i32* %15
%87 = load i32, i32* %16
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %85, i32 %86, i32 %87)
%89 = load i32, i32* %15
%90 = icmp eq i32 %89, 0
br i1 %90, label %94, label %91
91: ; preds = %83
%92 = load i32, i32* %16
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %91, %83
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %91
%100 = load i32, i32* %6
%101 = call i32 @listen(i32 %100, i32 2)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %107
103: ; preds = %99
%104 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
107: ; preds = %99
%108 = load i32, i32* @stdout
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0))
store i32 12, i32* %10
%110 = load i32, i32* %6
%111 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%112 = call i32 @accept(i32 %110, %struct.sockaddr* %111, i32* %10)
store i32 %112, i32* %7
%113 = load i32, i32* %7
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %119
115: ; preds = %107
%116 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%117 = load i32, i32* @EXIT_FAILURE
%118 = call i32 @exit(i32 %117)
unreachable
119: ; preds = %107
%120 = load i32, i32* @stdout
%121 = load i32, i32* @AF_INET
%122 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%123 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%124 = call i8* @inet_ntop(i32 %121, %struct.TYPE_2__* %122, i8* %123, i32 256)
%125 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%126 = load i32, i32* %125
%127 = call i32 @ntohs(i32 %126)
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %124, i32 %127)
%129 = call i32 @sleep(i32 5)
%130 = load i32, i32* @stdout
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0))
%132 = load i32, i32* %7
%133 = call i32 @close(i32 %132)
%134 = load i32, i32* %6
%135 = call i32 @close(i32 %134)
%136 = load i32, i32* @EXIT_SUCCESS
%137 = call i32 @exit(i32 %136)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Invocation: %s <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [12 x i8] c"getresgid()\00"
@stdout = global i32 0
@.str.3 = [29 x i8] c"UID: %u, EUID: %u, SUID: %u\0A\00"
@.str.4 = [23 x i8] c"Binding to port %u...\0A\00"
@.str.5 = [7 x i8] c"bind()\00"
@.str.6 = [34 x i8] c"Run server as unprivileged user!\0A\00"
@.str.7 = [9 x i8] c"listen()\00"
@.str.8 = [48 x i8] c"Server is listening for incoming connection...\0A\00"
@.str.9 = [9 x i8] c"accept()\00"
@.str.10 = [36 x i8] c"TCP connection accepted from %s:%d\0A\00"
@.str.11 = [53 x i8] c"Closing connected socket (sending FIN to client)...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = icmp eq i32 %0, 2
br i1 %17, label %24, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = load i32, i32* @PF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = tail call i32 @socket(i32 %28, i32 %29, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %24
%33 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %24
%37 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %38, i32* %39
%40 = load i32, i32* @INADDR_ANY
%41 = call i32 @htonl(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %41, i32* %42
%43 = call i32 @htons(i32 %27)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %43, i32* %44
%45 = call i32 @getresuid(i32* %7, i32* %8, i32* %9)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %36
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %36
%52 = load i32, i32* @stdout
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %54, i32 %55)
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = call i32 @bind(i32 %30, %struct.sockaddr* %59, i32 12)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %51
%63 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %51
%67 = call i32 @getresuid(i32* %7, i32* %8, i32* %9)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %66
%74 = load i32, i32* @stdout
%75 = load i32, i32* %7
%76 = load i32, i32* %8
%77 = load i32, i32* %9
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %75, i32 %76, i32 %77)
%79 = load i32, i32* %8
%80 = icmp eq i32 %79, 0
%81 = load i32, i32* %9
%82 = icmp eq i32 %81, 0
%83 = select i1 %80, i1 true, i1 %82
br i1 %83, label %84, label %89
84: ; preds = %73
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %73
%90 = call i32 @listen(i32 %30, i32 2)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; preds = %89
%97 = load i32, i32* @stdout
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0))
store i32 12, i32* %5
%99 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%100 = call i32 @accept(i32 %30, %struct.sockaddr* %99, i32* %5)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %106
102: ; preds = %96
%103 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %96
%107 = load i32, i32* @stdout
%108 = load i32, i32* @AF_INET
%109 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%110 = call i8* @inet_ntop(i32 %108, %struct.TYPE_2__* %109, i8* %13, i32 256)
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%112 = load i32, i32* %111
%113 = call i32 @ntohs(i32 %112)
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %110, i32 %113)
%115 = call i32 @sleep(i32 5)
%116 = load i32, i32* @stdout
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0))
%118 = call i32 @close(i32 %100)
%119 = call i32 @close(i32 %30)
%120 = load i32, i32* @EXIT_SUCCESS
%121 = call i32 @exit(i32 %120)
unreachable
}