#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__ {
  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_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
scalar_t__ fsetxattr(int, char *, char *, int /*<<< orphan*/,
                     int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char *message = "hello";
  int sock, ret;
  struct sockaddr_in server_addr;
  struct hostent *host = gethostbyname("localhost");
  char *label;
  char *attr = "security.SMACK64IPOUT";
  int port;
  if (argc != 3) {
    perror("Client: Argument missing, please provide port and  label for "
           "SMACK64IPOUT");
    return 2;
  }
  port = atoi(argv[1]);
  label = argv[2];
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("Client: Socket failure");
    return 2;
  }
  if (fsetxattr(sock, attr, label, strlen(label), 0) < 0) {
    perror("Client: Unable to set attribute ");
    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);
  ret =
      sendto(sock, message, strlen(message), 0,
             (const struct sockaddr *)&server_addr, sizeof(struct sockaddr_in));
  close(sock);
  if (ret < 0) {
    perror("Client: Error sending message\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe2b(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
lea    0xe25(%rip),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1211 <main+0x61>
lea    0xe26(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1366 <main+0x1b6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    126b <main+0xbb>
lea    0xe16(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1366 <main+0x1b6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
cmp    $0x0,%rax
jge    12c1 <main+0x111>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1366 <main+0x1b6>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1090 <bcopy@plt>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jge    135f <main+0x1af>
lea    0xd5a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1366 <main+0x1b6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe3c(%rip),%rdi
call   1080 <gethostbyname@plt>
cmp    $0x3,%ebp
jne    12b8 <main+0x108>
mov    %rax,%r12
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rbx
mov    0x2df6(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12c1 <main+0x111>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xdf1(%rip),%rsi
xor    %r14d,%r14d
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <fsetxattr@plt>
test   %rax,%rax
js     12ca <main+0x11a>
mov    0x0(%r13),%eax
mov    %eax,0x14(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x8(%r12),%rsi
lea    0xc(%rsp),%rdi
mov    (%r12),%edx
call   1090 <memmove@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
lea    0xd86(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x10,%r9d
call   1060 <sendto@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1070 <close@plt>
test   %ebx,%ebx
js     12de <main+0x12e>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd67(%rip),%rdi
jmp    12d1 <main+0x121>
lea    0xda8(%rip),%rdi
jmp    12d1 <main+0x121>
lea    0xdb6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%r14d
jmp    12a6 <main+0xf6>
lea    0xdc3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%r14d
jmp    12a6 <main+0xf6>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"hello\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [22 x i8] c"security.SMACK64IPOUT\00"
@.str.3 = [74 x i8] c"Client: Argument missing, please provide port and label for SMACK64IPOUT\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [23 x i8] c"Client: Socket failure\00"
@.str.5 = [33 x i8] c"Client: Unable to set attribute \00"
@.str.6 = [31 x i8] c"Client: Error sending message\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %0, 3
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.3, i64 0, i64 0))
br label %48
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %48
21: ; preds = %9
%22 = tail call i32 @strlen(i8* %14)
%23 = tail call i64 @fsetxattr(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %22, i32 0)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %48
27: ; preds = %21
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %28, i32* %29
%30 = tail call i32 @htons(i32 %12)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to i8*
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%36 = bitcast i32* %35 to i8*
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%40 = call i32 @bzero(i32* %39, i32 8)
%41 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%43 = call i32 @sendto(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %41, i32 0, %struct.sockaddr* %42, i32 16)
%44 = call i32 @close(i32 %17)
%45 = icmp slt i32 %43, 0
br i1 %45, label %46, label %48
46: ; preds = %27
%47 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %27, %46, %25, %19, %7
%49 = phi i32 [ 2, %7 ], [ 2, %19 ], [ 2, %25 ], [ 1, %46 ], [ 0, %27 ]
ret i32 %49
}