#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ isprint(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(void) {
  int sock, i;
  char buff[1600];
  sock = socket(27, SOCK_RAW, 0);
  if (sock < 0) {
    perror("socket");
    return 0;
  }
  printf("Worked! Abort with ^C\n");
  while (1) {
    memset(buff, 0, sizeof(buff));
    int ret = recv(sock, buff, sizeof(buff), 0);
    if (ret < 0) {
      perror("recvmsg");
      continue;
    } else {
      assert(ret <= sizeof(buff));
      printf("RECEIVED ......\n");
      printf("hex:\n");
      for (i = 0; i < ret; i++)
        printf("0x%.2x ", (uint8_t)buff[i]);
      printf("ascii:\n");
      for (i = 0; i < ret; i++)
        printf("%c ", isprint(buff[i]) ? buff[i] : '.');
      printf("\n\n");
      fflush(stdout);
    }
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    $0x1b,%edi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11cb <main+0x4b>
lea    0xe45(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x650(%rbp),%rdi
xor    %esi,%esi
mov    $0x640,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x650(%rbp),%rsi
mov    $0x640,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x654(%rbp)
cmpl   $0x0,-0x654(%rbp)
jge    1226 <main+0xa6>
lea    0xe02(%rip),%rdi
call   1090 <perror@plt>
jmp    11d9 <main+0x59>
movslq -0x654(%rbp),%rax
cmp    $0x640,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x654(%rbp),%eax
jge    129a <main+0x11a>
movslq -0xc(%rbp),%rax
movsbl -0x650(%rbp,%rax,1),%esi
ff
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1263 <main+0xe3>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x654(%rbp),%eax
jge    1322 <main+0x1a2>
movslq -0xc(%rbp),%rax
movsbl -0x650(%rbp,%rax,1),%edi
ff
call   1080 <isprint@plt>
cmp    $0x0,%rax
je     12f0 <main+0x170>
movslq -0xc(%rbp),%rax
movsbl -0x650(%rbp,%rax,1),%eax
ff
mov    %eax,-0x658(%rbp)
jmp    1300 <main+0x180>
mov    $0x2e,%eax
mov    %eax,-0x658(%rbp)
jmp    1300 <main+0x180>
mov    -0x658(%rbp),%esi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12af <main+0x12f>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    11d9 <main+0x59>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x658,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    $0x1b,%edi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     12f3 <main+0x163>
mov    %eax,%ebp
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
lea    0xe37(%rip),%r15
lea    0xe38(%rip),%r12
mov    %ebp,0xc(%rsp)
jmp    11fc <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe10(%rip),%rdi
call   10a0 <perror@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x640,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x640,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11f0 <main+0x60>
mov    %eax,%r13d
xor    %edi,%edi
cmp    $0x641,%eax
setb   %dil
call   1070 <assert@plt>
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
test   %r13d,%r13d
jne    1260 <main+0xd0>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
jmp    12d0 <main+0x140>
xchg   %ax,%ax
mov    %r13d,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x10(%rsp,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1270 <main+0xe0>
lea    0xdb7(%rip),%rdi
call   1040 <puts@plt>
test   %r13d,%r13d
jle    12d0 <main+0x140>
xor    %ebp,%ebp
jmp    12b8 <main+0x128>
nopl   (%rax)
movsbl 0x10(%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
je     12d0 <main+0x140>
movsbl 0x10(%rsp,%rbp,1),%edi
call   1090 <isprint@plt>
test   %rax,%rax
jne    12a0 <main+0x110>
mov    $0x2e,%esi
jmp    12a5 <main+0x115>
xchg   %ax,%ax
lea    0xd76(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0xc(%rsp),%ebp
jmp    11fc <main+0x6c>
lea    0xd06(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
add    $0x658,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SOCK_RAW = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [23 x i8] c"Worked! Abort with ^C\0A\00"
@.str.2 = [8 x i8] c"recvmsg\00"
@.str.3 = [17 x i8] c"RECEIVED ......\0A\00"
@.str.4 = [6 x i8] c"hex:\0A\00"
@.str.5 = [8 x i8] c"0x%.2x \00"
@.str.6 = [8 x i8] c"ascii:\0A\00"
@.str.7 = [4 x i8] c"%c \00"
@.str.8 = [3 x i8] c"\0A\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1600 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @SOCK_RAW
%7 = call i32 @socket(i32 27, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %22, %76
%15 = getelementptr inbounds [1600 x i8], [1600 x i8]* %4, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 1600)
%17 = load i32, i32* %2
%18 = getelementptr inbounds [1600 x i8], [1600 x i8]* %4, i64 0, i64 0
%19 = call i32 @recv(i32 %17, i8* %18, i32 1600, i32 0)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %14
24: ; preds = %14
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = icmp ule i64 %26, 1600
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %32
32: ; preds = %43, %24
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1600 x i8], [1600 x i8]* %4, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %32
46: ; preds = %32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %48
48: ; preds = %69, %46
%49 = load i32, i32* %3
%50 = load i32, i32* %5
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %72
52: ; preds = %48
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1600 x i8], [1600 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i64 @isprint(i8 signext %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1600 x i8], [1600 x i8]* %4, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
br label %66
65: ; preds = %52
br label %66
66: ; preds = %65, %59
%67 = phi i32 [ %64, %59 ], [ 46, %65 ]
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %66
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %48
72: ; preds = %48
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%74 = load i32, i32* @stdout
%75 = call i32 @fflush(i32 %74)
br label %76
76: ; preds = %72
br label %14
}

LLVM IR (-O2):
@SOCK_RAW = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"recvmsg\00"
@.str.5 = [8 x i8] c"0x%.2x \00"
@.str.7 = [4 x i8] c"%c \00"
@stdout = global i32 0
@str = [22 x i8] c"Worked! Abort with ^C\00"
@str.9 = [16 x i8] c"RECEIVED ......\00"
@str.10 = [5 x i8] c"hex:\00"
@str.11 = [7 x i8] c"ascii:\00"
@str.12 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [1600 x i8]
%2 = getelementptr inbounds [1600 x i8], [1600 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @SOCK_RAW
%4 = tail call i32 @socket(i32 27, i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %58, %8
%11 = call i32 @memset(i8* %2, i32 0, i32 1600)
%12 = call i32 @recv(i32 %4, i8* %2, i32 1600, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %58
16: ; preds = %10
%17 = icmp ult i32 %12, 1601
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
%22 = icmp eq i32 %12, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
br label %54
25: ; preds = %16
%26 = zext i32 %12 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %33, %27 ]
%29 = getelementptr inbounds [1600 x i8], [1600 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %28, 1
%34 = icmp eq i64 %33, %26
br i1 %34, label %35, label %27
35: ; preds = %27
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
%37 = icmp sgt i32 %12, 0
br i1 %37, label %38, label %54
38: ; preds = %35
%39 = zext i32 %12 to i64
br label %40
40: ; preds = %38, %49
%41 = phi i64 [ 0, %38 ], [ %52, %49 ]
%42 = getelementptr inbounds [1600 x i8], [1600 x i8]* %1, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = call i64 @isprint(i8 signext %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i8, i8* %42
%48 = sext i8 %47 to i32
br label %49
49: ; preds = %40, %46
%50 = phi i32 [ %48, %46 ], [ 46, %40 ]
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %50)
%52 = add nuw nsw i64 %41, 1
%53 = icmp eq i64 %52, %39
br i1 %53, label %54, label %40
54: ; preds = %49, %23, %35
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.12, i64 0, i64 0))
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
br label %58
58: ; preds = %54, %14
br label %10
}