#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_in6 {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ dieError(char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
scalar_t__ strlen(char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
void getAnswer(int sock, struct sockaddr_in6 *client_addr) {
  socklen_t clilen = sizeof(*client_addr);
  char buffer[1024];
  int lenAns = 0;
  do {
    memset(buffer, 0, 1024);
    if (recvfrom(sock, buffer, 1024, 0, (struct sockaddr *)client_addr,
                 &clilen) < 0) {
      dieError("recvfrom() failed", sock);
    } else if (strlen(buffer) > 0) {
      lenAns = (int)strtol(&buffer[0], NULL, 8);
      buffer[1024] = '\0';
      if (lenAns >= 0) {
        printf("%s", buffer + 1);
        if (lenAns == 0)
          break;
      }
    }
  } while (1);
}


x86 assembly (clang, -O0):
<getAnswer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x14(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0x0,%rax
jge    11d2 <getAnswer+0x72>
mov    -0x4(%rbp),%esi
lea    0xe38(%rip),%rdi
call   1080 <dieError@plt>
jmp    124c <getAnswer+0xec>
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    1247 <getAnswer+0xe7>
lea    -0x420(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    %eax,-0x424(%rbp)
movb   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x424(%rbp)
jl     1242 <getAnswer+0xe2>
lea    -0x420(%rbp),%rsi
add    $0x1,%rsi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x424(%rbp)
jne    123d <getAnswer+0xdd>
jmp    1260 <getAnswer+0x100>
jmp    1242 <getAnswer+0xe2>
jmp    1247 <getAnswer+0xe7>
jmp    124c <getAnswer+0xec>
jmp    1251 <getAnswer+0xf1>
mov    $0x1,%al
test   $0x1,%al
jne    1183 <getAnswer+0x23>
jmp    1260 <getAnswer+0x100>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAnswer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r12
lea    0xe71(%rip),%r13
jmp    11aa <getAnswer+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%esi
call   1080 <dieError@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1070 <recvfrom@plt>
test   %rax,%rax
js     11a0 <getAnswer+0x40>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    11aa <getAnswer+0x4a>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
movb   $0x0,0x410(%rsp)
test   %r14d,%r14d
js     11aa <getAnswer+0x4a>
lea    0xe0a(%rip),%rdi
lea    0x11(%rsp),%rsi
call   1040 <printf@plt>
test   %r14d,%r14d
jne    11aa <getAnswer+0x4a>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
@.str.1 = [3 x i8] c"%s\00"
define void @getAnswer(i32 %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in6*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %4
store i32 4, i32* %5
store i32 0, i32* %7
br label %8
8: ; preds = %42, %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 1024)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %4
%14 = bitcast %struct.sockaddr_in6* %13 to %struct.sockaddr*
%15 = call i64 @recvfrom(i32 %11, i8* %12, i32 1024, i32 0, %struct.sockaddr* %14, i32* %5)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i32, i32* %3
%19 = call i32 @dieError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %41
20: ; preds = %8
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i64 @strtol(i8* %25, i32* null, i32 8)
%27 = trunc i64 %26 to i32
store i32 %27, i32* %7
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1024
store i8 0, i8* %28
%29 = load i32, i32* %7
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %24
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
br label %43
38: ; preds = %31
br label %39
39: ; preds = %38, %24
br label %40
40: ; preds = %39, %20
br label %41
41: ; preds = %40, %17
br label %42
42: ; preds = %41
br i1 true, label %8, label %43
43: ; preds = %42, %37
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
@.str.1 = [3 x i8] c"%s\00"
define void @getAnswer(i32 %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
%8 = bitcast %struct.sockaddr_in6* %1 to %struct.sockaddr*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1024
br label %10
10: ; preds = %16, %2
%11 = call i32 @memset(i8* %6, i32 0, i32 1024)
%12 = call i64 @recvfrom(i32 %0, i8* %6, i32 1024, i32 0, %struct.sockaddr* %8, i32* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @dieError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %14, %20, %24, %17
br label %10
17: ; preds = %10
%18 = call i64 @strlen(i8* %6)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %16
20: ; preds = %17
%21 = call i64 @strtol(i8* nocapture %6, i32* null, i32 8)
%22 = trunc i64 %21 to i32
store i8 0, i8* %9
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %16
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%26 = icmp eq i32 %22, 0
br i1 %26, label %27, label %16
27: ; preds = %24
ret void
}