#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);
scalar_t__ malloc(int);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
char *read_from_client(int sock, struct sockaddr_in6 *client_addr) {
  char *buffer;
  socklen_t clilen = sizeof(*client_addr);
  buffer = (char *)malloc(7);
  if (recvfrom(sock, buffer, 7, 0, (struct sockaddr *)client_addr, &clilen) <
      0) {
    dieError("recvfrom() failed", sock);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<read_from_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    $0x7,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x7,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1040 <recvfrom@plt>
cmp    $0x0,%rax
jge    1188 <read_from_client+0x58>
mov    -0x4(%rbp),%esi
lea    0xe7d(%rip),%rdi
call   1050 <dieError@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
movl   $0x4,0xc(%rsp)
mov    $0x7,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x7,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
call   1040 <recvfrom@plt>
test   %rax,%rax
jns    1181 <read_from_client+0x51>
lea    0xe87(%rip),%rdi
mov    %r14d,%esi
call   1050 <dieError@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
define i8* @read_from_client(i32 %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in6*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %4
store i32 4, i32* %6
%7 = call i64 @malloc(i32 7)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %5
%9 = load i32, i32* %3
%10 = load i8*, i8** %5
%11 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %4
%12 = bitcast %struct.sockaddr_in6* %11 to %struct.sockaddr*
%13 = call i64 @recvfrom(i32 %9, i8* %10, i32 7, i32 0, %struct.sockaddr* %12, i32* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @dieError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %2
%19 = load i8*, i8** %5
ret i8* %19
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
define i8* @read_from_client(i32 %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%5 = tail call i64 @malloc(i32 7)
%6 = inttoptr i64 %5 to i8*
%7 = bitcast %struct.sockaddr_in6* %1 to %struct.sockaddr*
%8 = call i64 @recvfrom(i32 %0, i8* %6, i32 7, i32 0, %struct.sockaddr* %7, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @dieError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %12
12: ; preds = %10, %2
ret i8* %6
}