#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_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int Receiver(int sd) {
  char buffer[1024];
  struct sockaddr_in addr;
  do {
    int len = sizeof(addr);
    if (recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr *)&addr,
                 &len) > 0)
      printf("Got %s:%d \"%s\"\n", inet_ntoa(addr.sin_addr),
             ntohs(addr.sin_port), buffer);
    else
      perror("recvfrom");
  } while (strcmp(buffer, "bye\n") != 0);
  fprintf(stderr, "child exiting\n");
  exit(0);
}


x86 assembly (clang, -O0):
<Receiver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x8,-0x41c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x418(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x41c(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0x0,%rax
jle    1204 <Receiver+0x84>
mov    -0x414(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x428(%rbp)
mov    -0x418(%rbp),%edi
call   1080 <ntohs@plt>
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
lea    -0x410(%rbp),%rcx
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
jmp    1210 <Receiver+0x90>
lea    0xe05(%rip),%rdi
call   1090 <perror@plt>
jmp    1215 <Receiver+0x95>
lea    -0x410(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    118e <Receiver+0xe>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<Receiver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebp
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xe70(%rip),%r13
jmp    11e9 <Receiver+0x69>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r12
mov    0x8(%rsp),%edi
call   1080 <ntohs@plt>
lea    0xe34(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121b <Receiver+0x9b>
movl   $0x8,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1070 <recvfrom@plt>
test   %rax,%rax
jg     11b0 <Receiver+0x30>
lea    0xdfc(%rip),%rdi
call   1090 <perror@plt>
jmp    11d9 <Receiver+0x59>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Got %s:%d \22%s\22\0A\00"
@.str.1 = [9 x i8] c"recvfrom\00"
@.str.2 = [5 x i8] c"bye\0A\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"child exiting\0A\00"
define i32 @Receiver(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %24, %1
store i32 8, i32* %5
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%10 = call i64 @recvfrom(i32 %7, i8* %8, i32 1024, i32 0, %struct.sockaddr* %9, i32* %5)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i8* @inet_ntoa(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @ntohs(i32 %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %18, i8* %19)
br label %23
21: ; preds = %6
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %12
br label %24
24: ; preds = %23
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %6, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Got %s:%d \22%s\22\0A\00"
@.str.1 = [9 x i8] c"recvfrom\00"
@.str.2 = [5 x i8] c"bye\0A\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"child exiting\0A\00"
define i32 @Receiver(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %11
11: ; preds = %22, %1
store i32 8, i32* %4
%12 = call i64 @recvfrom(i32 %0, i8* %5, i32 1024, i32 0, %struct.sockaddr* %8, i32* %4)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %9
%16 = call i8* @inet_ntoa(i32 %15)
%17 = load i32, i32* %10
%18 = call i32 @ntohs(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18, i8* %5)
br label %22
20: ; preds = %11
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %11
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
}