#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*/ 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 *, 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(AF_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;
  while (1) {
    nBytes = recvfrom(udpSocket, buffer, 1024, 0,
                      (struct sockaddr *)&serverStorage, &addr_size);
    for (i = 0; i < nBytes - 1; i++)
      buffer[i] = toupper(buffer[i]);
    printf("%s", buffer);
    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    0x2e3f(%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)
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)
movl   $0x0,-0x444(%rbp)
mov    -0x444(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    129c <main+0x10c>
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    1250 <main+0xc0>
lea    -0x410(%rbp),%rsi
lea    0xd60(%rip),%rdi
call   1050 <printf@plt>
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    121f <main+0x8f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    0x2e40(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1ed3,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0xe28(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x10,%edx
call   10a0 <bind@plt>
movl   $0x4,0x4(%rsp)
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%r14
jmp    1246 <main+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xde3(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x4(%rsp),%r9d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <sendto@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
lea    0x4(%rsp),%r9
call   1090 <recvfrom@plt>
mov    %eax,%ebp
cmp    $0x2,%eax
jl     1220 <main+0x90>
lea    -0x1(%rbp),%r15d
xor    %r12d,%r12d
xchg   %ax,%ax
movsbl 0x20(%rsp,%r12,1),%edi
call   1030 <toupper@plt>
mov    %al,0x20(%rsp,%r12,1)
add    $0x1,%r12
cmp    %r12,%r15
jne    1270 <main+0xe0>
jmp    1220 <main+0x90>

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 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [3 x i8] c"%s\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* @AF_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
br label %27
27: ; preds = %0, %49
%28 = load i32, i32* %2
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%31 = call i32 @recvfrom(i32 %28, i8* %29, i32 1024, i32 0, %struct.sockaddr* %30, i32* %8)
store i32 %31, i32* %3
store i32 0, i32* %10
br label %32
32: ; preds = %46, %27
%33 = load i32, i32* %10
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = call signext i8 @toupper(i8 signext %41)
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %37
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %32
49: ; preds = %32
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = load i32, i32* %2
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%54 = load i32, i32* %3
%55 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%56 = load i32, i32* %8
%57 = call i32 @sendto(i32 %52, i8* %53, i32 %54, i32 0, %struct.sockaddr* %55, i32 %56)
br label %27
}

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 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [3 x i8] c"%s\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* @AF_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 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
br label %22
22: ; preds = %35, %0
%23 = call i32 @recvfrom(i32 %11, i8* %5, i32 1024, i32 0, %struct.sockaddr* %21, i32* %4)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = add nsw i32 %23, -1
%27 = zext i32 %26 to i64
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ 0, %25 ], [ %33, %28 ]
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call signext i8 @toupper(i8 signext %31)
store i8 %32, i8* %30
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28, %22
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%37 = load i32, i32* %4
%38 = call i32 @sendto(i32 %11, i8* %5, i32 %23, i32 0, %struct.sockaddr* %21, i32 %37)
br label %22
}