#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int c;
  struct sockaddr_in server;
  char msg[1000];
  int yes = 1;
  c = socket(AF_INET, SOCK_DGRAM, 0);
  if (c < 0) {
    printf("Eroare la crearea socketului...\n");
    ;
    return 1;
  }
  setsockopt(c, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int));
  memset(&server, 0, sizeof(server));
  server.sin_port = htons(12345);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("172.30.255.255");
  int i;
  char buffer[1000];
  while (1) {
    fgets(buffer, sizeof(buffer), stdin);
    if ((strlen(buffer) > 0) && (buffer[strlen(buffer) - 1] == '\n'))
      buffer[strlen(buffer) - 1] = '\0';
    sprintf(msg, "[Krisztian] %s", buffer);
    sendto(c, msg, sizeof(msg), 0, (struct sockaddr *)&server,
           (socklen_t)sizeof(server));
  }
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x404(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fc <main+0x5c>
lea    0xe17(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x7f0,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    -0x404(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdce(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
lea    -0x7f0(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1090 <fgets@plt>
lea    -0x7f0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    12c5 <main+0x125>
lea    -0x7f0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x7f0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12c5 <main+0x125>
lea    -0x7f0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x7f0(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rdx
lea    0xd56(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x400(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x3e8,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
jmp    125b <main+0xbb>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f8,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12c8 <main+0x128>
mov    %eax,%r12d
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    $0x3039,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
lea    0xdcf(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    0x2d97(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0xdc2(%rip),%r15
lea    0x410(%rsp),%rbp
jmp    1289 <main+0xe9>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1260 <main+0xc0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1260 <main+0xc0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1260 <main+0xc0>
lea    0xd4f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x7f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [33 x i8] c"Eroare la crearea socketului...\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [15 x i8] c"172.30.255.255\00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"[Krisztian] %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 1, i32* %5
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret i32 1
15: ; preds = %0
%16 = load i32, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_BROADCAST
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %5, i32 4)
%20 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%21 = call i32 @htons(i32 12345)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %23, i32* %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
br label %28
28: ; preds = %15, %50
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %29, i32 1000, i32 %30)
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %28
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %44, %35, %28
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %2
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%56 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%57 = call i32 @sendto(i32 %54, i8* %55, i32 1000, i32 0, %struct.sockaddr* %56, i32 12)
br label %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [15 x i8] c"172.30.255.255\00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"[Krisztian] %s\00"
@str = [32 x i8] c"Eroare la crearea socketului...\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1000 x i8]
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
ret i32 1
14: ; preds = %0
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_BROADCAST
%17 = call i32 @setsockopt(i32 %10, i32 %15, i32 %16, i32* %3, i32 4)
%18 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%19 = call i32 @htons(i32 12345)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %21, i32* %22
%23 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %27
27: ; preds = %44, %14
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %25, i32 1000, i32 %28)
%30 = call i32 @strlen(i8* %25)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %27
%33 = call i32 @strlen(i8* %25)
%34 = add nsw i32 %33, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = call i32 @strlen(i8* %25)
%41 = add nsw i32 %40, -1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %39, %32, %27
%45 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%46 = call i32 @sendto(i32 %10, i8* %6, i32 1000, i32 0, %struct.sockaddr* %26, i32 12)
br label %27
}