#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 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;
  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]);
    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    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
mov    $0x1ed3,%edi
call   1040 <htons@plt>
mov    %eax,-0x418(%rbp)
lea    0xe2c(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x420(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x10,%edx
call   1090 <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   1080 <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    128c <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    1240 <main+0xc0>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x438(%rbp),%r8
mov    -0x43c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
jmp    120f <main+0x8f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r13d
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1ed3,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0xe31(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x10,%edx
call   1090 <bind@plt>
movl   $0x4,0x4(%rsp)
lea    0x20(%rsp),%r14
lea    0x8(%rsp),%r15
jmp    1227 <main+0xa7>
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%r9d
mov    %r13d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1060 <sendto@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
lea    0x4(%rsp),%r9
call   1080 <recvfrom@plt>
mov    %eax,%ebx
cmp    $0x2,%eax
jl     1210 <main+0x90>
lea    -0x1(%rbx),%ebp
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,%rbp
jne    1250 <main+0xd0>
jmp    1210 <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 }
@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"
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
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 = load i32, i32* %2
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%52 = load i32, i32* %3
%53 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%54 = load i32, i32* %8
%55 = call i32 @sendto(i32 %50, i8* %51, i32 %52, i32 0, %struct.sockaddr* %53, i32 %54)
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 }
@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"
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 = 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 = load i32, i32* %4
%37 = call i32 @sendto(i32 %11, i8* %5, i32 %23, i32 0, %struct.sockaddr* %21, i32 %36)
br label %22
}