#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 /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int ipc_connect(char *);
int ipc_rcvmsg(int, char *, int);
int /*<<< orphan*/ ipc_sndmsg(int, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int s, quit, r;
  char buffer[256];
  fd_set rfds;
  setvbuf(stdout, NULL, _IONBF, 0);
  s = ipc_connect(argv[1]);
  FD_ZERO(&rfds);
  for (quit = 0; !quit;) {
    FD_SET(s, &rfds);
    FD_SET(0, &rfds);
    bzero(buffer, 256);
    select(s + 1, &rfds, NULL, NULL, NULL);
    if (FD_ISSET(0, &rfds)) {
      buffer[255] = 0;
      r = read(0, buffer, 255);
      if (r > 0) {
        buffer[r - 1] = 0;
        ipc_sndmsg(s, buffer, -1);
      } else {
        quit = 1;
      }
    }
    if (FD_ISSET(s, &rfds)) {
      buffer[255] = 0;
      r = ipc_rcvmsg(s, buffer, 255);
      if (r >= 0) {
        printf("GOT: %s\n", buffer);
      } else {
        quit = 1;
      }
    }
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <ipc_connect@plt>
mov    %eax,-0x14(%rbp)
lea    -0x124(%rbp),%rdi
call   1090 <FD_ZERO@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122f <main+0x6f>
jmp    1352 <main+0x192>
mov    -0x14(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   10e0 <FD_SET@plt>
xor    %edi,%edi
lea    -0x124(%rbp),%rsi
call   10e0 <FD_SET@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x124(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <select@plt>
xor    %edi,%edi
lea    -0x124(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12eb <main+0x12b>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rsi
xor    %edi,%edi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12df <main+0x11f>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xffffffff,%edx
call   1050 <ipc_sndmsg@plt>
jmp    12e6 <main+0x126>
movl   $0x1,-0x18(%rbp)
jmp    12eb <main+0x12b>
mov    -0x14(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     134d <main+0x18d>
movb   $0x0,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   10c0 <ipc_rcvmsg@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1341 <main+0x181>
lea    -0x120(%rbp),%rsi
lea    0xcc9(%rip),%rdi
call   1060 <printf@plt>
jmp    1348 <main+0x188>
movl   $0x1,-0x18(%rbp)
jmp    134d <main+0x18d>
jmp    1219 <main+0x59>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    0x8(%rbx),%rdi
call   1030 <ipc_connect@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1090 <FD_ZERO@plt>
mov    %ebx,%r15d
add    $0x1,%r15d
lea    0x10(%rsp),%r13
lea    0xde6(%rip),%r12
jmp    1234 <main+0x74>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
test   %bpl,%bpl
je     12e4 <main+0x124>
mov    %ebx,%edi
mov    %r14,%rsi
call   10e0 <FD_SET@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   10e0 <FD_SET@plt>
mov    %r13,%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <select@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
mov    $0x1,%bpl
test   %rax,%rax
je     12b2 <main+0xf2>
movb   $0x0,0x10f(%rsp)
xor    %edi,%edi
mov    %r13,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    12b0 <main+0xf0>
add    $0xffffffff,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0xffffffff,%edx
call   1050 <ipc_sndmsg@plt>
jmp    12b2 <main+0xf2>
nopl   (%rax)
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     122b <main+0x6b>
movb   $0x0,0x10f(%rsp)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0xff,%edx
call   10c0 <ipc_rcvmsg@plt>
test   %eax,%eax
jns    1220 <main+0x60>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [9 x i8] c"GOT: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @stdout
%12 = load i32, i32* @_IONBF
%13 = call i32 @setvbuf(i32 %11, i32* null, i32 %12, i32 0)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @ipc_connect(i8* %16)
store i32 %17, i32* %6
%18 = call i32 @FD_ZERO(i32* %10)
store i32 0, i32* %7
br label %19
19: ; preds = %66, %2
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %67
23: ; preds = %19
%24 = load i32, i32* %6
%25 = call i32 @FD_SET(i32 %24, i32* %10)
%26 = call i32 @FD_SET(i32 0, i32* %10)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = call i32 @bzero(i8* %27, i32 256)
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = call i32 @select(i32 %30, i32* %10, i32* null, i32* null, i32* null)
%32 = call i64 @FD_ISSET(i32 0, i32* %10)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %23
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %35
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%37 = call i32 @read(i32 0, i8* %36, i32 255)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %34
%41 = load i32, i32* %8
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %6
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%47 = call i32 @ipc_sndmsg(i32 %45, i8* %46, i32 -1)
br label %49
48: ; preds = %34
store i32 1, i32* %7
br label %49
49: ; preds = %48, %40
br label %50
50: ; preds = %49, %23
%51 = load i32, i32* %6
%52 = call i64 @FD_ISSET(i32 %51, i32* %10)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %55
%56 = load i32, i32* %6
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%58 = call i32 @ipc_rcvmsg(i32 %56, i8* %57, i32 255)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp sge i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %54
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%63 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %62)
br label %65
64: ; preds = %54
store i32 1, i32* %7
br label %65
65: ; preds = %64, %61
br label %66
66: ; preds = %65, %50
br label %19
67: ; preds = %19
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [9 x i8] c"GOT: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = tail call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @ipc_connect(i8* %11)
%13 = call i32 @FD_ZERO(i32* %4)
%14 = add nsw i32 %12, 1
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
br label %16
16: ; preds = %2, %40
%17 = call i32 @FD_SET(i32 %12, i32* %4)
%18 = call i32 @FD_SET(i32 0, i32* %4)
%19 = call i32 @bzero(i8* %5, i32 256)
%20 = call i32 @select(i32 %14, i32* %4, i32* null, i32* null, i32* null)
%21 = call i64 @FD_ISSET(i32 0, i32* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %16
store i8 0, i8* %15
%24 = call i32 @read(i32 0, i8* %5, i32 255)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = add nsw i32 %24, -1
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i32 @ipc_sndmsg(i32 %12, i8* %5, i32 -1)
br label %31
31: ; preds = %23, %26, %16
%32 = phi i1 [ false, %23 ], [ true, %26 ], [ true, %16 ]
%33 = call i64 @FD_ISSET(i32 %12, i32* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %31
store i8 0, i8* %15
%36 = call i32 @ipc_rcvmsg(i32 %12, i8* %5, i32 255)
%37 = icmp sgt i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
40: ; preds = %38, %31
br i1 %32, label %16, label %41
41: ; preds = %35, %40
%42 = call i32 @close(i32 %12)
ret i32 0
}