#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;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDTIMEO;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ fsetxattr(int, char *, char *, int /*<<< orphan*/,
                     int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sock;
  char message[255] = "hello";
  struct sockaddr_in server_addr;
  char *label_in;
  char *label_out;
  char *attr_out = "security.SMACK64IPOUT";
  char *attr_in = "security.SMACK64IPIN";
  char out[256];
  int port;
  struct timeval timeout;
  timeout.tv_sec = 15;
  timeout.tv_usec = 0;
  struct hostent *host = gethostbyname("localhost");
  if (argc != 4) {
    perror("Client: Arguments missing, please provide socket labels");
    return 2;
  }
  port = atoi(argv[1]);
  label_in = argv[2];
  label_out = argv[3];
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Client: Socket failure");
    return 2;
  }
  if (fsetxattr(sock, attr_out, label_out, strlen(label_out), 0) < 0) {
    perror("Client: Unable to set attribute SMACK64IPOUT");
    return 2;
  }
  if (fsetxattr(sock, attr_in, label_in, strlen(label_in), 0) < 0) {
    perror("Client: Unable to set attribute SMACK64IPIN");
    return 2;
  }
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(port);
  bcopy((char *)host->h_addr, (char *)&server_addr.sin_addr.s_addr,
        host->h_length);
  bzero(&(server_addr.sin_zero), 8);
  if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) <
      0) {
    perror("Client: Set timeout failed\n");
    return 2;
  }
  if (connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) ==
      -1) {
    perror("Client: Connection failure");
    close(sock);
    return 1;
  }
  if (write(sock, message, strlen(message)) < 0) {
    perror("Client: Error sending data\n");
    close(sock);
    return 1;
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <memset@plt>
movb   $0x68,-0x120(%rbp)
movb   $0x65,-0x11f(%rbp)
movb   $0x6c,-0x11e(%rbp)
movb   $0x6c,-0x11d(%rbp)
movb   $0x6f,-0x11c(%rbp)
lea    0xdca(%rip),%rax
mov    %rax,-0x148(%rbp)
lea    0xdd2(%rip),%rax
mov    %rax,-0x150(%rbp)
movl   $0xf,-0x268(%rbp)
movq   $0x0,-0x260(%rbp)
lea    0xdc4(%rip),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x270(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1295 <main+0xb5>
lea    0xdb1(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x254(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x140(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1303 <main+0x123>
lea    0xd7b(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x14(%rbp),%eax
mov    %eax,-0x284(%rbp)
mov    -0x148(%rbp),%rax
mov    %rax,-0x280(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,-0x278(%rbp)
mov    -0x140(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x284(%rbp),%edi
mov    -0x280(%rbp),%rsi
mov    -0x278(%rbp),%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
cmp    $0x0,%rax
jge    1374 <main+0x194>
lea    0xd21(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x14(%rbp),%eax
mov    %eax,-0x29c(%rbp)
mov    -0x150(%rbp),%rax
mov    %rax,-0x298(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x290(%rbp)
mov    -0x138(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x29c(%rbp),%edi
mov    -0x298(%rbp),%rsi
mov    -0x290(%rbp),%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
cmp    $0x0,%rax
jge    13e5 <main+0x205>
lea    0xcdd(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    0x2bec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
mov    -0x254(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x128(%rbp)
mov    -0x270(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x130(%rbp),%rsi
add    $0x4,%rsi
mov    -0x270(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
lea    -0x130(%rbp),%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    -0x14(%rbp),%edi
mov    0x2b9c(%rip),%rax
mov    (%rax),%esi
mov    0x2ba3(%rip),%rax
mov    (%rax),%edx
lea    -0x268(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1483 <main+0x2a3>
lea    0xc6b(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x4,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    14c0 <main+0x2e0>
lea    0xc52(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2ac(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x2a8(%rbp)
lea    -0x120(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x2ac(%rbp),%edi
mov    -0x2a8(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1521 <main+0x341>
lea    0xc0c(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1530 <main+0x350>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movups %xmm0,0x10f(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x6c6c6568,0x20(%rsp)
6c
movb   $0x6f,0x24(%rsp)
movl   $0xf,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xdaf(%rip),%rdi
call   1090 <gethostbyname@plt>
cmp    $0x4,%ebp
jne    13ac <main+0x1dc>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%r12
mov    0x18(%rbx),%rbp
mov    0x2d30(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     13b5 <main+0x1e5>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0xd2b(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
test   %rax,%rax
js     13be <main+0x1ee>
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0xd1a(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
test   %rax,%rax
js     13c7 <main+0x1f7>
mov    0x0(%r13),%eax
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rsi
lea    0x4(%rsp),%rdi
mov    (%r14),%edx
call   10a0 <memmove@plt>
mov    %rsp,%rdi
mov    $0x8,%esi
call   10c0 <bzero@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
mov    0x2c9a(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     13d0 <main+0x200>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     13e3 <main+0x213>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     13ec <main+0x21c>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    1404 <main+0x234>
lea    0xc82(%rip),%rdi
jmp    13d7 <main+0x207>
lea    0xcb1(%rip),%rdi
jmp    13d7 <main+0x207>
lea    0xcbf(%rip),%rdi
jmp    13d7 <main+0x207>
lea    0xce3(%rip),%rdi
jmp    13d7 <main+0x207>
lea    0xd06(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%eax
jmp    1404 <main+0x234>
lea    0xd0f(%rip),%rdi
jmp    13f3 <main+0x223>
lea    0xd21(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
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.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"security.SMACK64IPOUT\00"
@.str.1 = [21 x i8] c"security.SMACK64IPIN\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [56 x i8] c"Client: Arguments missing, please provide socket labels\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [23 x i8] c"Client: Socket failure\00"
@.str.5 = [45 x i8] c"Client: Unable to set attribute SMACK64IPOUT\00"
@.str.6 = [44 x i8] c"Client: Unable to set attribute SMACK64IPIN\00"
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str.7 = [28 x i8] c"Client: Set timeout failed\0A\00"
@.str.8 = [27 x i8] c"Client: Connection failure\00"
@.str.9 = [28 x i8] c"Client: Error sending data\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [255 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [256 x i8]
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [255 x i8]* %7 to i8*
%18 = bitcast i8* %17 to [255 x i8]*
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i32 0, i32 0
store i8 104, i8* %19
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i32 0, i32 1
store i8 101, i8* %20
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i32 0, i32 2
store i8 108, i8* %21
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i32 0, i32 3
store i8 108, i8* %22
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %18, i32 0, i32 4
store i8 111, i8* %23
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %12
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 15, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i64 0, i64* %25
%26 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %26, %struct.hostent** %16
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 4
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %117
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %14
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
store i8* %38, i8** %9
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
store i8* %41, i8** %10
%42 = load i32, i32* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @socket(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %31
%47 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %117
48: ; preds = %31
%49 = load i32, i32* %6
%50 = load i8*, i8** %11
%51 = load i8*, i8** %10
%52 = load i8*, i8** %10
%53 = call i32 @strlen(i8* %52)
%54 = call i64 @fsetxattr(i32 %49, i8* %50, i8* %51, i32 %53, i32 0)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %117
58: ; preds = %48
%59 = load i32, i32* %6
%60 = load i8*, i8** %12
%61 = load i8*, i8** %9
%62 = load i8*, i8** %9
%63 = call i32 @strlen(i8* %62)
%64 = call i64 @fsetxattr(i32 %59, i8* %60, i8* %61, i32 %63, i32 0)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %58
%67 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %117
68: ; preds = %58
%69 = load i32, i32* @AF_INET
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %69, i32* %70
%71 = load i32, i32* %14
%72 = call i32 @htons(i32 %71)
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %72, i32* %73
%74 = load %struct.hostent*, %struct.hostent** %16
%75 = getelementptr inbounds %struct.hostent, %struct.hostent* %74, i32 0, i32 1
%76 = load i64, i64* %75
%77 = inttoptr i64 %76 to i8*
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%79 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %78, i32 0, i32 0
%80 = bitcast i32* %79 to i8*
%81 = load %struct.hostent*, %struct.hostent** %16
%82 = getelementptr inbounds %struct.hostent, %struct.hostent* %81, i32 0, i32 0
%83 = load i32, i32* %82
%84 = call i32 @bcopy(i8* %77, i8* %80, i32 %83)
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%86 = call i32 @bzero(i32* %85, i32 8)
%87 = load i32, i32* %6
%88 = load i32, i32* @SOL_SOCKET
%89 = load i32, i32* @SO_SNDTIMEO
%90 = call i64 @setsockopt(i32 %87, i32 %88, i32 %89, %struct.timeval* %15, i32 16)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %68
%93 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
store i32 2, i32* %3
br label %117
94: ; preds = %68
%95 = load i32, i32* %6
%96 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%97 = call i32 @connect(i32 %95, %struct.sockaddr* %96, i32 4)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %103
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%101 = load i32, i32* %6
%102 = call i32 @close(i32 %101)
store i32 1, i32* %3
br label %117
103: ; preds = %94
%104 = load i32, i32* %6
%105 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%106 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%107 = call i32 @strlen(i8* %106)
%108 = call i64 @write(i32 %104, i8* %105, i32 %107)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %103
%111 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%112 = load i32, i32* %6
%113 = call i32 @close(i32 %112)
store i32 1, i32* %3
br label %117
114: ; preds = %103
%115 = load i32, i32* %6
%116 = call i32 @close(i32 %115)
store i32 0, i32* %3
br label %117
117: ; preds = %114, %110, %99, %92, %66, %56, %46, %29
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"security.SMACK64IPOUT\00"
@.str.1 = [21 x i8] c"security.SMACK64IPIN\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [56 x i8] c"Client: Arguments missing, please provide socket labels\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [23 x i8] c"Client: Socket failure\00"
@.str.5 = [45 x i8] c"Client: Unable to set attribute SMACK64IPOUT\00"
@.str.6 = [44 x i8] c"Client: Unable to set attribute SMACK64IPIN\00"
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str.7 = [28 x i8] c"Client: Set timeout failed\0A\00"
@.str.8 = [27 x i8] c"Client: Connection failure\00"
@.str.9 = [28 x i8] c"Client: Error sending data\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 104, i8* %6
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 1
store i8 101, i8* %7
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 2
store i8 108, i8* %8
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 3
store i8 108, i8* %9
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 4
store i8 111, i8* %10
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast %struct.timeval* %5 to i8*
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 15, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %14
%15 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %0, 4
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %81
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = tail call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %81
33: ; preds = %19
%34 = tail call i32 @strlen(i8* %26)
%35 = tail call i64 @fsetxattr(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %34, i32 0)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
br label %81
39: ; preds = %33
%40 = tail call i32 @strlen(i8* %24)
%41 = tail call i64 @fsetxattr(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %40, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
br label %81
45: ; preds = %39
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %46, i32* %47
%48 = tail call i32 @htons(i32 %22)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %48, i32* %49
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 1
%51 = load i64, i64* %50
%52 = inttoptr i64 %51 to i8*
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%54 = bitcast i32* %53 to i8*
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%58 = call i32 @bzero(i32* %57, i32 8)
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_SNDTIMEO
%61 = call i64 @setsockopt(i32 %29, i32 %59, i32 %60, %struct.timeval* %5, i32 16)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %45
%64 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %81
65: ; preds = %45
%66 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%67 = call i32 @connect(i32 %29, %struct.sockaddr* %66, i32 4)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%71 = call i32 @close(i32 %29)
br label %81
72: ; preds = %65
%73 = call i32 @strlen(i8* %6)
%74 = call i64 @write(i32 %29, i8* %6, i32 %73)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%78 = call i32 @close(i32 %29)
br label %81
79: ; preds = %72
%80 = call i32 @close(i32 %29)
br label %81
81: ; preds = %79, %76, %69, %63, %43, %37, %31, %17
%82 = phi i32 [ 2, %17 ], [ 2, %31 ], [ 2, %37 ], [ 2, %43 ], [ 2, %63 ], [ 1, %69 ], [ 1, %76 ], [ 0, %79 ]
ret i32 %82
}