#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ opcion;
typedef int /*<<< orphan*/ cadena;
typedef int /*<<< orphan*/ Servidor;
typedef int /*<<< orphan*/ Cliente;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int recvfrom(int, int *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
main() {
  int Socket_Servidor;
  struct sockaddr_in Servidor;
  int opcion = -1;
  struct tm *info;
  time_t timelocal;
  char cadena[100];
  struct sockaddr_in Cliente;
  socklen_t Longitud_Cliente;
  Socket_Servidor = socket(AF_INET, SOCK_DGRAM, 0);
  if (Socket_Servidor == -1) {
    printf("No se puede abrir socket servidor\n");
    exit(-1);
  }
  Servidor.sin_family = AF_INET;
  Servidor.sin_port = htons(2000);
  Servidor.sin_addr.s_addr = INADDR_ANY;
  if (bind(Socket_Servidor, (struct sockaddr *)&Servidor, sizeof(Servidor)) ==
      -1) {
    close(Socket_Servidor);
  }
  Longitud_Cliente = sizeof(Cliente);
  while (1) {
    int recibido = recvfrom(Socket_Servidor, &opcion, sizeof(opcion), 0,
                            (struct sockaddr *)&Cliente, &Longitud_Cliente);
    if (recibido > 0) {
      time(&timelocal);
      info = localtime(&timelocal);
      switch (opcion) {
      case 0:
        strftime(cadena, 100, "%d", info);
        break;
      case 1:
        strftime(cadena, 100, "%T", info);
        break;
      case 2:
        strftime(cadena, 100, "%d %T", info);
        break;
      }
      int enviado = sendto(Socket_Servidor, cadena, sizeof(cadena), 0,
                           (struct sockaddr *)&Cliente, Longitud_Cliente);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1205 <main+0x55>
lea    0xe0a(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x7d0,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    124c <main+0x9c>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0xc,-0xa4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%r8
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
lea    -0xa4(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
jle    1370 <main+0x1c0>
lea    -0x2c(%rbp),%rdi
mov    %rdi,-0xb8(%rbp)
call   1080 <time@plt>
mov    -0xb8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xb0(%rbp)
test   %eax,%eax
je     12e8 <main+0x138>
jmp    12c0 <main+0x110>
mov    -0xb0(%rbp),%eax
sub    $0x1,%eax
je     1309 <main+0x159>
jmp    12d4 <main+0x124>
mov    -0xb0(%rbp),%eax
sub    $0x2,%eax
je     132a <main+0x17a>
jmp    1346 <main+0x196>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x64,%esi
lea    0xd24(%rip),%rdx
call   10b0 <strftime@plt>
jmp    1346 <main+0x196>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x64,%esi
lea    0xd09(%rip),%rdx
call   10b0 <strftime@plt>
jmp    1346 <main+0x196>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x64,%esi
lea    0xce5(%rip),%rdx
call   10b0 <strftime@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0xa0(%rbp),%r8
mov    -0xa4(%rbp),%r9d
mov    $0x64,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0xac(%rbp)
jmp    1256 <main+0xa6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
mov    0x2e18(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12bf <main+0x10f>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x7d0,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    122d <main+0x7d>
mov    %ebx,%edi
call   1070 <close@plt>
movl   $0xc,0x8(%rsp)
lea    0xc(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x1c(%rsp),%r13
lea    0x30(%rsp),%rbp
jmp    1269 <main+0xb9>
mov    0x8(%rsp),%r9d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1060 <sendto@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
test   %eax,%eax
jle    1269 <main+0xb9>
mov    %r13,%rdi
call   1080 <time@plt>
mov    %r13,%rdi
call   1030 <localtime@plt>
movslq 0xc(%rsp),%rcx
cmp    $0x2,%rcx
ja     1250 <main+0xa0>
lea    0xd86(%rip),%rsi
movslq (%rsi,%rcx,4),%rdx
add    %rsi,%rdx
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   10b0 <strftime@plt>
jmp    1250 <main+0xa0>
lea    0xd43(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [35 x i8] c"No se puede abrir socket servidor\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%T\00"
@.str.3 = [6 x i8] c"%d %T\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %4
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 2000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%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
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %32, %20
store i32 12, i32* %9
br label %36
36: ; preds = %35, %64
%37 = load i32, i32* %2
%38 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%39 = call i32 @recvfrom(i32 %37, i32* %4, i32 4, i32 0, %struct.sockaddr* %38, i32* %9)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %64
42: ; preds = %36
%43 = call i32 @time(i32* %6)
%44 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %44, %struct.tm** %5
%45 = load i32, i32* %4
switch i32 %45, label %58 [
i32 0, label %46
i32 1, label %50
i32 2, label %54
]
46: ; preds = %42
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%48 = load %struct.tm*, %struct.tm** %5
%49 = call i32 @strftime(i8* %47, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %48)
br label %58
50: ; preds = %42
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%52 = load %struct.tm*, %struct.tm** %5
%53 = call i32 @strftime(i8* %51, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %52)
br label %58
54: ; preds = %42
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%56 = load %struct.tm*, %struct.tm** %5
%57 = call i32 @strftime(i8* %55, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %56)
br label %58
58: ; preds = %42, %54, %50, %46
%59 = load i32, i32* %2
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%61 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%62 = load i32, i32* %9
%63 = call i32 @sendto(i32 %59, i8* %60, i32 100, i32 0, %struct.sockaddr* %61, i32 %62)
store i32 %63, i32* %11
br label %64
64: ; preds = %58, %36
br label %36
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.tm = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%T\00"
@.str.3 = [6 x i8] c"%d %T\00"
@str = [34 x i8] c"No se puede abrir socket servidor\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 2000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i32 @bind(i32 %15, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @close(i32 %15)
br label %32
32: ; preds = %30, %20
store i32 12, i32* %6
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %34
34: ; preds = %50, %32
%35 = call i32 @recvfrom(i32 %15, i32* %2, i32 4, i32 0, %struct.sockaddr* %33, i32* %6)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = call i32 @time(i32* %3)
%39 = call %struct.tm* @localtime(i32* %3)
%40 = load i32, i32* %2
%41 = icmp ult i32 %40, 3
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = sext i32 %40 to i64
%44 = shl i64 %43, 2
%45 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %44)
%46 = call i32 @strftime(i8* %10, i32 100, i8* %45, %struct.tm* %39)
br label %47
47: ; preds = %37, %42
%48 = load i32, i32* %6
%49 = call i32 @sendto(i32 %15, i8* %10, i32 100, i32 0, %struct.sockaddr* %33, i32 %48)
br label %50
50: ; preds = %47, %34
br label %34
}