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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int lf_receive_packet(char *, int *);
int lf_send(char *, int);
int /*<<< orphan*/ lf_socket_init(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  const char *path = "socket.sock";
  char data[(5)];
  int ret, got_data;
  lf_socket_init((char *)path);
  while (1) {
    ret = lf_receive_packet((char *)&data, &got_data);
    if (ret != 0) {
      exit(1);
    }
    if (got_data) {
      data[(5) - 1] = '\0';
      printf("lf_receive '%s'\n", (char *)&data);
      ret = lf_send((char *)&data, (5));
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <lf_socket_init@plt>
lea    -0x15(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <lf_receive_packet@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1197 <main+0x47>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     11c6 <main+0x76>
movb   $0x0,-0x11(%rbp)
lea    -0x15(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x15(%rbp),%rdi
mov    $0x5,%esi
call   1070 <lf_send@plt>
mov    %eax,-0x1c(%rbp)
jmp    1173 <main+0x23>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
call   1050 <lf_socket_init@plt>
lea    0xb(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1030 <lf_receive_packet@plt>
test   %eax,%eax
jne    11c5 <main+0x75>
lea    0xb(%rsp),%rbx
lea    0x4(%rsp),%r14
lea    0xe83(%rip),%r15
jmp    119f <main+0x4f>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <lf_receive_packet@plt>
test   %eax,%eax
jne    11c5 <main+0x75>
cmpl   $0x0,0x4(%rsp)
je     1190 <main+0x40>
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <lf_send@plt>
jmp    1190 <main+0x40>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"socket.sock\00"
@.str.1 = [17 x i8] c"lf_receive '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @lf_socket_init(i8* %6)
br label %8
8: ; preds = %0, %24
%9 = bitcast [5 x i8]* %3 to i8*
%10 = call i32 @lf_receive_packet(i8* %9, i32* %5)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
store i8 0, i8* %19
%20 = bitcast [5 x i8]* %3 to i8*
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = bitcast [5 x i8]* %3 to i8*
%23 = call i32 @lf_send(i8* %22, i32 5)
store i32 %23, i32* %4
br label %24
24: ; preds = %18, %15
br label %8
}

LLVM IR (-O2):
@.str = [12 x i8] c"socket.sock\00"
@.str.1 = [17 x i8] c"lf_receive '%s'\0A\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @lf_socket_init(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @lf_receive_packet(i8* %3, i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
br label %12
10: ; preds = %18, %0
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %8, %18
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
store i8 0, i8* %9
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%17 = call i32 @lf_send(i8* %3, i32 5)
br label %18
18: ; preds = %15, %12
%19 = call i32 @lf_receive_packet(i8* %3, i32* %2)
%20 = icmp eq i32 %19, 0
br i1 %20, label %12, label %10
}