#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 sockaddr_storage {
  int dummy;
};
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*/ serverAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char toupper(char);
int main() {
  int udpSocket, nBytes;
  char buffer[1024];
  struct sockaddr_in serverAddr, clientAddr;
  struct sockaddr_storage serverStorage;
  socklen_t addr_size, client_addr_size;
  int i;
  udpSocket = socket(PF_INET, SOCK_DGRAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(7891);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  bind(udpSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
  addr_size = sizeof serverStorage;
  printf("Server listening...: \n");
  while (1) {
    nBytes = recvfrom(udpSocket, buffer, 1024, 0,
                      (struct sockaddr *)&serverStorage, &addr_size);
    printf("Received from client: %s\n", buffer);
    for (i = 0; i < nBytes - 1; i++)
      buffer[i] = toupper(buffer[i]);
    sendto(udpSocket, buffer, nBytes, 0, (struct sockaddr *)&serverStorage,
           addr_size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
mov    $0x1ed3,%edi
call   1040 <htons@plt>
mov    %eax,-0x418(%rbp)
lea    0xe1c(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x420(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <bind@plt>
movl   $0x4,-0x43c(%rbp)
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x438(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x43c(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x444(%rbp)
mov    -0x444(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12bf <main+0x12f>
movslq -0x444(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x444(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x444(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x444(%rbp)
jmp    1273 <main+0xe3>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x438(%rbp),%r8
mov    -0x43c(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
jmp    122d <main+0x9d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r13d
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1ed3,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0xe11(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x10,%edx
call   10b0 <bind@plt>
movl   $0x4,0x4(%rsp)
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%r14
jmp    1257 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%r9d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1080 <sendto@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
lea    0x4(%rsp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,%ebp
lea    0xd90(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x2,%ebp
jl     1240 <main+0xa0>
lea    -0x1(%rbp),%r15d
xor    %r12d,%r12d
movsbl 0x20(%rsp,%r12,1),%edi
call   1030 <toupper@plt>
mov    %al,0x20(%rsp,%r12,1)
add    $0x1,%r12
cmp    %r12,%r15
jne    1290 <main+0xf0>
jmp    1240 <main+0xa0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [23 x i8] c"Server listening...: \0A\00"
@.str.2 = [26 x i8] c"Received from client: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 3
store i32 %14, i32* %15
%16 = call i32 @htons(i32 7891)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @memset(i32 %22, i8 signext 0, i32 4)
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i32 @bind(i32 %24, %struct.sockaddr* %25, i32 16)
store i32 4, i32* %8
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %0, %52
%29 = load i32, i32* %2
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%32 = call i32 @recvfrom(i32 %29, i8* %30, i32 1024, i32 0, %struct.sockaddr* %31, i32* %8)
store i32 %32, i32* %3
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 0, i32* %10
br label %35
35: ; preds = %49, %28
%36 = load i32, i32* %10
%37 = load i32, i32* %3
%38 = sub nsw i32 %37, 1
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = call signext i8 @toupper(i8 signext %44)
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %47
store i8 %45, i8* %48
br label %49
49: ; preds = %40
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %35
52: ; preds = %35
%53 = load i32, i32* %2
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%55 = load i32, i32* %3
%56 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%57 = load i32, i32* %8
%58 = call i32 @sendto(i32 %53, i8* %54, i32 %55, i32 0, %struct.sockaddr* %56, i32 %57)
br label %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.2 = [26 x i8] c"Received from client: %s\0A\00"
@str = [22 x i8] c"Server listening...: \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_storage* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 3
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 7891)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%19 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%20 = call i32 @bind(i32 %11, %struct.sockaddr* %19, i32 16)
store i32 4, i32* %4
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%22 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
br label %23
23: ; preds = %37, %0
%24 = call i32 @recvfrom(i32 %11, i8* %5, i32 1024, i32 0, %struct.sockaddr* %22, i32* %4)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%26 = icmp sgt i32 %24, 1
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = add nsw i32 %24, -1
%29 = zext i32 %28 to i64
br label %30
30: ; preds = %27, %30
%31 = phi i64 [ 0, %27 ], [ %35, %30 ]
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call signext i8 @toupper(i8 signext %33)
store i8 %34, i8* %32
%35 = add nuw nsw i64 %31, 1
%36 = icmp eq i64 %35, %29
br i1 %36, label %37, label %30
37: ; preds = %30, %23
%38 = load i32, i32* %4
%39 = call i32 @sendto(i32 %11, i8* %5, i32 %24, i32 0, %struct.sockaddr* %22, i32 %38)
br label %23
}