#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 /*<<< orphan*/ timeout;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ message;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
scalar_t__ fsetxattr(int, char *, char *, int /*<<< orphan*/,
                     int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sock, ret;
  struct sockaddr_in server_addr, client_addr;
  socklen_t len;
  char message[5];
  char *label;
  char *attr = "security.SMACK64IPIN";
  int port;
  if (argc != 3) {
    perror("Server: Argument missing, please provide port and label for "
           "SMACK64IPIN");
    return 2;
  }
  port = atoi(argv[1]);
  label = argv[2];
  struct timeval timeout;
  timeout.tv_sec = 15;
  timeout.tv_usec = 0;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("Server: Socket error");
    return 2;
  }
  if (fsetxattr(sock, attr, label, strlen(label), 0) < 0) {
    perror("Server: Unable to set attribute ");
    return 2;
  }
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(port);
  server_addr.sin_addr.s_addr = INADDR_ANY;
  bzero(&(server_addr.sin_zero), 8);
  if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) <
      0) {
    perror("Server: Set timeout failed\n");
    return 2;
  }
  if (bind(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
    perror("Server: Bind failure");
    return 2;
  }
  len = sizeof(client_addr);
  ret = recvfrom(sock, message, sizeof(message), 0,
                 (struct sockaddr *)&client_addr, &len);
  close(sock);
  if (ret < 0) {
    perror("Server: Error receiving");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f6 <main+0x46>
lea    0xe30(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bb <main+0x20b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
movl   $0xf,-0x70(%rbp)
movq   $0x0,-0x68(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    125f <main+0xaf>
lea    0xe0f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bb <main+0x20b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
cmp    $0x0,%rax
jge    12bb <main+0x10b>
lea    0xdc8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bb <main+0x20b>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x5c(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    -0x14(%rbp),%edi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
mov    0x2cc1(%rip),%rax
mov    (%rax),%edx
lea    -0x70(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1332 <main+0x182>
lea    0xd72(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bb <main+0x20b>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1365 <main+0x1b5>
lea    0xd5b(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bb <main+0x20b>
movl   $0x10,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x41(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x5,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jge    13b4 <main+0x204>
lea    0xd21(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bb <main+0x20b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jne    12e9 <main+0x139>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rbp
movl   $0xf,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2df2(%rip),%r15
mov    (%r15),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12f2 <main+0x142>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0xde6(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
test   %rax,%rax
js     12fb <main+0x14b>
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
lea    0x28(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1304 <main+0x154>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     130d <main+0x15d>
movl   $0x10,0xc(%rsp)
lea    0x23(%rsp),%rsi
xor    %r14d,%r14d
lea    0x38(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1080 <recvfrom@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1070 <close@plt>
test   %ebp,%ebp
jns    131f <main+0x16f>
lea    0xde8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%r14d
jmp    131f <main+0x16f>
lea    0xd25(%rip),%rdi
jmp    1314 <main+0x164>
lea    0xd64(%rip),%rdi
jmp    1314 <main+0x164>
lea    0xd70(%rip),%rdi
jmp    1314 <main+0x164>
lea    0xd88(%rip),%rdi
jmp    1314 <main+0x164>
lea    0xd9b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"security.SMACK64IPIN\00"
@.str.1 = [72 x i8] c"Server: Argument missing, please provide port and label for SMACK64IPIN\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [21 x i8] c"Server: Socket error\00"
@.str.3 = [33 x i8] c"Server: Unable to set attribute \00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.4 = [28 x i8] c"Server: Set timeout failed\0A\00"
@.str.5 = [21 x i8] c"Server: Bind failure\00"
@.str.6 = [24 x i8] c"Server: Error receiving\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [5 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %13
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %84
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %12
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 15, i32* %28
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i64 0, i64* %29
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_DGRAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %20
%36 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %84
37: ; preds = %20
%38 = load i32, i32* %6
%39 = load i8*, i8** %13
%40 = load i8*, i8** %12
%41 = load i8*, i8** %12
%42 = call i32 @strlen(i8* %41)
%43 = call i64 @fsetxattr(i32 %38, i8* %39, i8* %40, i32 %42, i32 0)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %84
47: ; preds = %37
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %48, i32* %49
%50 = load i32, i32* %14
%51 = call i32 @htons(i32 %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %51, i32* %52
%53 = load i32, i32* @INADDR_ANY
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
store i32 %53, i32* %55
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%57 = call i32 @bzero(i32* %56, i32 8)
%58 = load i32, i32* %6
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_RCVTIMEO
%61 = call i64 @setsockopt(i32 %58, i32 %59, i32 %60, %struct.timeval* %15, i32 16)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %47
%64 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %84
65: ; preds = %47
%66 = load i32, i32* %6
%67 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%68 = call i64 @bind(i32 %66, %struct.sockaddr* %67, i32 16)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %84
72: ; preds = %65
store i32 16, i32* %10
%73 = load i32, i32* %6
%74 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%75 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%76 = call i32 @recvfrom(i32 %73, i8* %74, i32 5, i32 0, %struct.sockaddr* %75, i32* %10)
store i32 %76, i32* %7
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* %7
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %72
%82 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %84
83: ; preds = %72
store i32 0, i32* %3
br label %84
84: ; preds = %83, %81, %70, %63, %45, %35, %18
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"security.SMACK64IPIN\00"
@.str.1 = [72 x i8] c"Server: Argument missing, please provide port and label for SMACK64IPIN\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [21 x i8] c"Server: Socket error\00"
@.str.3 = [33 x i8] c"Server: Unable to set attribute \00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.4 = [28 x i8] c"Server: Set timeout failed\0A\00"
@.str.5 = [21 x i8] c"Server: Bind failure\00"
@.str.6 = [24 x i8] c"Server: Error receiving\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [5 x i8]
%7 = alloca %struct.timeval
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%12 = icmp eq i32 %0, 3
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %66
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = bitcast %struct.timeval* %7 to i8*
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 15, i32* %22
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %23
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = tail call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %15
%29 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %64
30: ; preds = %15
%31 = tail call i32 @strlen(i8* %20)
%32 = tail call i64 @fsetxattr(i32 %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %31, i32 0)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %64
36: ; preds = %30
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %37, i32* %38
%39 = tail call i32 @htons(i32 %18)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %39, i32* %40
%41 = load i32, i32* @INADDR_ANY
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%44 = call i32 @bzero(i32* %43, i32 8)
%45 = load i32, i32* @SOL_SOCKET
%46 = load i32, i32* @SO_RCVTIMEO
%47 = call i64 @setsockopt(i32 %26, i32 %45, i32 %46, %struct.timeval* %7, i32 16)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %36
%50 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %64
51: ; preds = %36
%52 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%53 = call i64 @bind(i32 %26, %struct.sockaddr* %52, i32 16)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %64
57: ; preds = %51
store i32 16, i32* %5
%58 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%59 = call i32 @recvfrom(i32 %26, i8* %11, i32 5, i32 0, %struct.sockaddr* %58, i32* %5)
%60 = call i32 @close(i32 %26)
%61 = icmp slt i32 %59, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %57, %62, %55, %49, %34, %28
%65 = phi i32 [ 2, %28 ], [ 2, %34 ], [ 2, %49 ], [ 2, %55 ], [ 1, %62 ], [ 0, %57 ]
br label %66
66: ; preds = %64, %13
%67 = phi i32 [ 2, %13 ], [ %65, %64 ]
ret i32 %67
}