#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  register int sfd;
  int addr_len;
  struct sockaddr_in server_addr;
  int numbytes;
  char buf[100];
  char usage[100];
  int portnumber;
  const int portnumberdefault = 13;
  sprintf(usage,
          "Utilisation: %s [numéroport ] (0 <= port_number <= 65535)\nExample: "
          "%s 1024\n",
          argv[0], argv[0]);
  switch (argc) {
  case 1:
    portnumber = portnumberdefault;
    break;
  case 2:
    if (sscanf(argv[1], "%d", &portnumber) == 0)
      exit(2);
    if (!((portnumber > 0) && (portnumber < 65535)))
      exit(3);
    break;
  default:
    printf("%s", usage);
    exit(1);
  }
  if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(4);
  }
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(portnumber);
  inet_aton("127.0.0.1", &(server_addr.sin_addr));
  memset(&(server_addr.sin_zero), '\0', 8);
  addr_len = sizeof(struct sockaddr);
  if ((sendto(sfd, "", 0, 0, (struct sockaddr *)&server_addr, addr_len)) < 0) {
    perror("daytimed-udp send");
    close(sfd);
    exit(5);
  }
  if ((numbytes = recvfrom(sfd, buf, (int)sizeof(buf), MSG_DONTWAIT,
                           (struct sockaddr *)&server_addr, &addr_len)) < 0) {
    perror("recvfrom");
    close(sfd);
    exit(7);
  }
  buf[numbytes] = '\0';
  printf("%s", buf);
  close(sfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xd,-0x108(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe0f(%rip),%rsi
lea    -0x100(%rbp),%rdi
mov    %rcx,%rdx
call   10c0 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10c(%rbp)
sub    $0x1,%eax
je     122b <main+0x6b>
jmp    1217 <main+0x57>
mov    -0x10c(%rbp),%eax
sub    $0x2,%eax
je     123a <main+0x7a>
jmp    1294 <main+0xd4>
movl   $0xd,-0x104(%rbp)
jmp    12b1 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe04(%rip),%rsi
lea    -0x104(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%eax
jne    1268 <main+0xa8>
mov    $0x2,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x104(%rbp)
jle    1285 <main+0xc5>
cmpl   $0xffff,-0x104(%rbp)
jl     128f <main+0xcf>
mov    $0x3,%edi
call   10d0 <exit@plt>
jmp    12b1 <main+0xf1>
lea    -0x100(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12ec <main+0x12c>
lea    0xd76(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x104(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
lea    0xd45(%rip),%rdi
call   1080 <inet_aton@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%r8
mov    -0x18(%rbp),%r9d
lea    0xd09(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    1374 <main+0x1b4>
lea    0xd07(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x5,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    0x2c4b(%rip),%rax
mov    (%rax),%ecx
lea    -0x28(%rbp),%r8
mov    $0x64,%edx
lea    -0x18(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    13c3 <main+0x203>
lea    0xcca(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x7,%edi
call   10d0 <exit@plt>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xc73(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rcx
lea    0xe28(%rip),%rsi
lea    0x90(%rsp),%rdi
mov    %rcx,%rdx
call   10c0 <sprintf@plt>
cmp    $0x2,%ebp
je     122e <main+0x6e>
cmp    $0x1,%ebp
jne    1255 <main+0x95>
movl   $0xd,0x8(%rsp)
mov    0x2de7(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
jns    1273 <main+0xb3>
lea    0xe34(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>
mov    0x8(%rbx),%rdi
lea    0xe14(%rip),%rsi
lea    0x8(%rsp),%rdx
call   10a0 <sscanf@plt>
test   %eax,%eax
jne    12f3 <main+0x133>
mov    $0x2,%edi
call   10d0 <exit@plt>
lea    0xdf4(%rip),%rdi
lea    0x90(%rsp),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x1c(%rsp)
mov    0x8(%rsp),%edi
call   1030 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x14(%rsp),%rsi
lea    0xdc5(%rip),%rdi
call   1080 <inet_aton@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x4,0xc(%rsp)
lea    0xd8f(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0x4,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
jns    130f <main+0x14f>
lea    0xd87(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0x5,%edi
call   10d0 <exit@plt>
mov    0x8(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0xfffe,%eax
jb     11fa <main+0x3a>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%ecx
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0x64,%edx
call   1090 <recvfrom@plt>
test   %eax,%eax
jns    1354 <main+0x194>
lea    0xd38(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0x7,%edi
call   10d0 <exit@plt>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xcee(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [77 x i8] c"Utilisation: %s [num\C3\A9roport ] (0 <= port_number <= 65535)\0AExample: %s 1024\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%s\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [10 x i8] c"127.0.0.1\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [18 x i8] c"daytimed-udp send\00"
@MSG_DONTWAIT = global i32 0
@.str.7 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [100 x i8]
%11 = alloca [100 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 13, i32* %13
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %20)
%22 = load i32, i32* %4
switch i32 %22, label %41 [
i32 1, label %23
i32 2, label %24
]
23: ; preds = %2
store i32 13, i32* %12
br label %45
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @exit(i32 2)
unreachable
32: ; preds = %24
%33 = load i32, i32* %12
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %12
%37 = icmp slt i32 %36, 65535
br i1 %37, label %40, label %38
38: ; preds = %35, %32
%39 = call i32 @exit(i32 3)
unreachable
40: ; preds = %35
br label %45
41: ; preds = %2
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %40, %23
%46 = load i32, i32* @AF_INET
%47 = load i32, i32* @SOCK_DGRAM
%48 = call i32 @socket(i32 %46, i32 %47, i32 0)
store i32 %48, i32* %6
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 4)
unreachable
53: ; preds = %45
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %54, i32* %55
%56 = load i32, i32* %12
%57 = call i32 @htons(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%60 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%62 = call i32 @memset(i32* %61, i8 signext 0, i32 8)
store i32 4, i32* %7
%63 = load i32, i32* %6
%64 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%65 = load i32, i32* %7
%66 = call i64 @sendto(i32 %63, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 0, i32 0, %struct.sockaddr* %64, i32 %65)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %53
%69 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32, i32* %6
%71 = call i32 @close(i32 %70)
%72 = call i32 @exit(i32 5)
unreachable
73: ; preds = %53
%74 = load i32, i32* %6
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%76 = load i32, i32* @MSG_DONTWAIT
%77 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%78 = call i32 @recvfrom(i32 %74, i8* %75, i32 100, i32 %76, %struct.sockaddr* %77, i32* %7)
store i32 %78, i32* %9
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %73
%81 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = call i32 @close(i32 %82)
%84 = call i32 @exit(i32 7)
unreachable
85: ; preds = %73
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%90 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %89)
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
%93 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [77 x i8] c"Utilisation: %s [num\C3\A9roport ] (0 <= port_number <= 65535)\0AExample: %s 1024\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%s\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [10 x i8] c"127.0.0.1\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [18 x i8] c"daytimed-udp send\00"
@MSG_DONTWAIT = global i32 0
@.str.7 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = load i8*, i8** %1
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %13)
switch i32 %0, label %29 [
i32 1, label %15
i32 2, label %16
]
15: ; preds = %2
store i32 13, i32* %7
br label %32
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %16
%24 = load i32, i32* %7
%25 = add i32 %24, -1
%26 = icmp ult i32 %25, 65534
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = call i32 @exit(i32 3)
unreachable
29: ; preds = %2
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23, %15
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 4)
unreachable
40: ; preds = %32
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %41, i32* %42
%43 = load i32, i32* %7
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %44, i32* %45
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%47 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%49 = call i32 @memset(i32* %48, i8 signext 0, i32 8)
store i32 4, i32* %3
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i64 @sendto(i32 %35, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 0, i32 0, %struct.sockaddr* %50, i32 4)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %40
%54 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @close(i32 %35)
%56 = call i32 @exit(i32 5)
unreachable
57: ; preds = %40
%58 = load i32, i32* @MSG_DONTWAIT
%59 = call i32 @recvfrom(i32 %35, i8* %10, i32 100, i32 %58, %struct.sockaddr* %50, i32* %3)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 @close(i32 %35)
%64 = call i32 @exit(i32 7)
unreachable
65: ; preds = %57
%66 = zext i32 %59 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %66
store i8 0, i8* %67
%68 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%69 = call i32 @close(i32 %35)
%70 = call i32 @exit(i32 0)
unreachable
}