#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_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_GETFL;
int O_NONBLOCK;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SUN_LEN(struct sockaddr_un *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ do_msg(int, int);
int do_return_msg(int);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
size_t strlen(char *);
size_t strlen_utf8(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    fprintf(stderr, "socket needed\n");
    return 1;
  }
  char *socket_file = argv[1];
  int i;
  char *msg;
  size_t msg_len;
  size_t msg_len_utf8;
  char s_msg_len[6];
  char buf[1024];
  int socket_fd;
  struct sockaddr_un name;
  fd_set read_fds;
  socket_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
  name.sun_family = AF_LOCAL;
  strcpy(name.sun_path, socket_file);
  if (connect(socket_fd, (struct sockaddr *)&name, SUN_LEN(&name)) == -1) {
    perror(argv[0]);
  }
  int flags = fcntl(socket_fd, F_GETFL, 0);
  fcntl(socket_fd, F_GETFL, flags | O_NONBLOCK);
  flags = fcntl(0, F_GETFL, 0);
  fcntl(0, F_GETFL, flags | O_NONBLOCK);
  sprintf(s_msg_len, "%06x", argc - 2);
  write(socket_fd, s_msg_len, 6);
  for (i = 2; i < argc; ++i) {
    msg = argv[i];
    msg_len = strlen(msg);
    msg_len_utf8 = strlen_utf8(msg);
    sprintf(s_msg_len, "%06x", msg_len_utf8);
    write(socket_fd, s_msg_len, 6);
    write(socket_fd, msg, msg_len);
  }
  fflush(NULL);
  int s = 0;
  int n = 0;
  while (1) {
    FD_ZERO(&read_fds);
    FD_SET(0, &read_fds);
    FD_SET(socket_fd, &read_fds);
    s = select(FD_SETSIZE, &read_fds, NULL, NULL, NULL);
    if (s < 0) {
      break;
    } else if (s == 0) {
      continue;
    }
    if (FD_ISSET(socket_fd, &read_fds)) {
      n = read(socket_fd, buf, 1);
      if (n == 0) {
        break;
      }
      switch (*buf) {
      case 'o':
        do_msg(socket_fd, 1);
        break;
      case 'e':
        do_msg(socket_fd, 2);
        break;
      case 'r':
        return do_return_msg(socket_fd);
      default:
        fprintf(stderr, "Protocol error.\n");
        return -1;
      }
    }
    if (FD_ISSET(0, &read_fds)) {
      n = read(0, buf, 1024);
      write(socket_fd, buf, n);
      fflush(NULL);
      if (n == 0) {
        break;
      }
    }
  }
  close(socket_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1284 <main+0x44>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1650 <main+0x410>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x444(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x450(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x444(%rbp),%eax
mov    %eax,-0x46c(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x450(%rbp),%rdi
call   1150 <SUN_LEN@plt>
mov    -0x46c(%rbp),%edi
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    131c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <perror@plt>
mov    -0x444(%rbp),%edi
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x458(%rbp)
mov    -0x444(%rbp),%edi
mov    0x2c73(%rip),%rax
mov    (%rax),%esi
mov    -0x458(%rbp),%edx
mov    0x2c94(%rip),%rax
or     (%rax),%edx
call   1040 <fcntl@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1040 <fcntl@plt>
mov    %eax,-0x458(%rbp)
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
mov    -0x458(%rbp),%edx
mov    0x2c5f(%rip),%rax
or     (%rax),%edx
xor    %edi,%edi
call   1040 <fcntl@plt>
lea    -0x3e(%rbp),%rdi
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
movslq %eax,%rdx
lea    0xc69(%rip),%rsi
call   1120 <sprintf@plt>
mov    -0x444(%rbp),%edi
lea    -0x3e(%rbp),%rsi
mov    $0x6,%edx
call   1050 <write@plt>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1447 <main+0x207>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <strlen_utf8@plt>
mov    %rax,-0x38(%rbp)
lea    -0x3e(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xc04(%rip),%rsi
call   1120 <sprintf@plt>
mov    -0x444(%rbp),%edi
lea    -0x3e(%rbp),%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    -0x444(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13c6 <main+0x186>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <fflush@plt>
movl   $0x0,-0x45c(%rbp)
movl   $0x0,-0x460(%rbp)
lea    -0x454(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x454(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x444(%rbp),%edi
lea    -0x454(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    -0x454(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10e0 <select@plt>
mov    %eax,-0x45c(%rbp)
cmpl   $0x0,-0x45c(%rbp)
jge    14c8 <main+0x288>
jmp    163e <main+0x3fe>
cmpl   $0x0,-0x45c(%rbp)
jne    14da <main+0x29a>
jmp    1464 <main+0x224>
jmp    14df <main+0x29f>
mov    -0x444(%rbp),%edi
lea    -0x454(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15d0 <main+0x390>
mov    -0x444(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    %eax,-0x460(%rbp)
cmpl   $0x0,-0x460(%rbp)
jne    152a <main+0x2ea>
jmp    163e <main+0x3fe>
movsbl -0x440(%rbp),%eax
mov    %eax,-0x470(%rbp)
sub    $0x65,%eax
je     1582 <main+0x342>
jmp    1545 <main+0x305>
mov    -0x470(%rbp),%eax
sub    $0x6f,%eax
je     156d <main+0x32d>
jmp    1559 <main+0x319>
mov    -0x470(%rbp),%eax
sub    $0x72,%eax
je     1597 <main+0x357>
jmp    15aa <main+0x36a>
mov    -0x444(%rbp),%edi
mov    $0x1,%esi
call   1100 <do_msg@plt>
jmp    15cb <main+0x38b>
mov    -0x444(%rbp),%edi
mov    $0x2,%esi
call   1100 <do_msg@plt>
jmp    15cb <main+0x38b>
mov    -0x444(%rbp),%edi
call   10b0 <do_return_msg@plt>
mov    %eax,-0x4(%rbp)
jmp    1650 <main+0x410>
mov    0x2a1f(%rip),%rax
mov    (%rax),%edi
lea    0xa5a(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1650 <main+0x410>
jmp    15d0 <main+0x390>
xor    %edi,%edi
lea    -0x454(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1639 <main+0x3f9>
lea    -0x440(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x460(%rbp)
mov    -0x444(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x460(%rbp),%edx
call   1050 <write@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <fflush@plt>
cmpl   $0x0,-0x460(%rbp)
jne    1634 <main+0x3f4>
jmp    163e <main+0x3fe>
jmp    1639 <main+0x3f9>
jmp    1464 <main+0x224>
mov    -0x444(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
cmp    $0x1,%edi
jne    1275 <main+0x35>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%eax
jmp    149a <main+0x25a>
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%r15
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1150 <SUN_LEN@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
je     14d7 <main+0x297>
mov    0x2cdf(%rip),%r15
mov    (%r15),%esi
mov    %r13d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    (%r15),%esi
mov    0x2cf8(%rip),%r14
or     (%r14),%eax
mov    %r13d,%edi
mov    %eax,%edx
call   1040 <fcntl@plt>
mov    (%r15),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    (%r15),%esi
or     (%r14),%eax
xor    %edi,%edi
mov    %eax,%edx
call   1040 <fcntl@plt>
lea    -0x2(%rbx),%eax
movslq %eax,%rdx
lea    0xcea(%rip),%rsi
lea    0x2(%rsp),%r15
mov    %r15,%rdi
call   1120 <sprintf@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x6,%edx
call   1050 <write@plt>
cmp    $0x3,%ebx
jl     13b8 <main+0x178>
mov    %ebx,%eax
mov    %rax,0x8(%rsp)
mov    $0x2,%r15d
lea    0x2(%rsp),%r12
nopl   0x0(%rax)
mov    0x0(%rbp,%r15,8),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbp,%r14
mov    %rax,%rbp
mov    %rbx,%rdi
call   1080 <strlen_utf8@plt>
mov    %r12,%rdi
lea    0xc8a(%rip),%rsi
mov    %rax,%rdx
call   1120 <sprintf@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14,%rbp
call   1050 <write@plt>
add    $0x1,%r15
cmp    %r15,0x8(%rsp)
jne    1360 <main+0x120>
xor    %edi,%edi
call   10f0 <fflush@plt>
lea    0x1c(%rsp),%rbx
mov    0x2bf5(%rip),%r15
lea    0x20(%rsp),%r14
mov    %rbx,%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10e0 <select@plt>
test   %eax,%eax
js     1490 <main+0x250>
je     13d0 <main+0x190>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1450 <main+0x210>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
test   %eax,%eax
je     1490 <main+0x250>
movsbl 0x20(%rsp),%eax
cmp    $0x65,%eax
je     1443 <main+0x203>
mov    $0x1,%esi
cmp    $0x6f,%eax
je     1448 <main+0x208>
jmp    14ac <main+0x26c>
mov    $0x2,%esi
mov    %r13d,%edi
call   1100 <do_msg@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13d0 <main+0x190>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,%ebp
mov    %r13d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   10f0 <fflush@plt>
test   %ebp,%ebp
jne    13d0 <main+0x190>
mov    %r13d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x72,%eax
jne    14bb <main+0x27b>
mov    %r13d,%edi
call   10b0 <do_return_msg@plt>
jmp    149a <main+0x25a>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
lea    0xb49(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    149a <main+0x25a>
mov    0x0(%rbp),%rdi
call   1110 <perror@plt>
jmp    12d2 <main+0x92>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"socket needed\0A\00"
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [5 x i8] c"%06x\00"
@FD_SETSIZE = global i32 0
@.str.2 = [17 x i8] c"Protocol error.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca [6 x i8]
%12 = alloca [1024 x i8]
%13 = alloca i32
%14 = alloca %struct.sockaddr_un
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %164
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %6
%28 = load i32, i32* @PF_LOCAL
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %13
%31 = load i32, i32* @AF_LOCAL
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %14, i32 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %14, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i8*, i8** %6
%36 = call i32 @strcpy(i32 %34, i8* %35)
%37 = load i32, i32* %13
%38 = bitcast %struct.sockaddr_un* %14 to %struct.sockaddr*
%39 = call i32 @SUN_LEN(%struct.sockaddr_un* %14)
%40 = call i32 @connect(i32 %37, %struct.sockaddr* %38, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %24
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @perror(i8* %45)
br label %47
47: ; preds = %42, %24
%48 = load i32, i32* %13
%49 = load i32, i32* @F_GETFL
%50 = call i32 @fcntl(i32 %48, i32 %49, i32 0)
store i32 %50, i32* %16
%51 = load i32, i32* %13
%52 = load i32, i32* @F_GETFL
%53 = load i32, i32* %16
%54 = load i32, i32* @O_NONBLOCK
%55 = or i32 %53, %54
%56 = call i32 @fcntl(i32 %51, i32 %52, i32 %55)
%57 = load i32, i32* @F_GETFL
%58 = call i32 @fcntl(i32 0, i32 %57, i32 0)
store i32 %58, i32* %16
%59 = load i32, i32* @F_GETFL
%60 = load i32, i32* %16
%61 = load i32, i32* @O_NONBLOCK
%62 = or i32 %60, %61
%63 = call i32 @fcntl(i32 0, i32 %59, i32 %62)
%64 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%65 = load i32, i32* %4
%66 = sub nsw i32 %65, 2
%67 = sext i32 %66 to i64
%68 = call i32 @sprintf(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %67)
%69 = load i32, i32* %13
%70 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%71 = call i32 @write(i32 %69, i8* %70, i32 6)
store i32 2, i32* %7
br label %72
72: ; preds = %97, %47
%73 = load i32, i32* %7
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %100
76: ; preds = %72
%77 = load i8**, i8*** %5
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
store i8* %81, i8** %8
%82 = load i8*, i8** %8
%83 = call i64 @strlen(i8* %82)
store i64 %83, i64* %9
%84 = load i8*, i8** %8
%85 = call i64 @strlen_utf8(i8* %84)
store i64 %85, i64* %10
%86 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%87 = load i64, i64* %10
%88 = call i32 @sprintf(i8* %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %87)
%89 = load i32, i32* %13
%90 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%91 = call i32 @write(i32 %89, i8* %90, i32 6)
%92 = load i32, i32* %13
%93 = load i8*, i8** %8
%94 = load i64, i64* %9
%95 = trunc i64 %94 to i32
%96 = call i32 @write(i32 %92, i8* %93, i32 %95)
br label %97
97: ; preds = %76
%98 = load i32, i32* %7
%99 = add nsw i32 %98, 1
store i32 %99, i32* %7
br label %72
100: ; preds = %72
%101 = call i32 @fflush(i32* null)
store i32 0, i32* %17
store i32 0, i32* %18
br label %102
102: ; preds = %100, %115, %160
%103 = call i32 @FD_ZERO(i32* %15)
%104 = call i32 @FD_SET(i32 0, i32* %15)
%105 = load i32, i32* %13
%106 = call i32 @FD_SET(i32 %105, i32* %15)
%107 = load i32, i32* @FD_SETSIZE
%108 = call i32 @select(i32 %107, i32* %15, i32* null, i32* null, i32* null)
store i32 %108, i32* %17
%109 = load i32, i32* %17
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %102
br label %161
112: ; preds = %102
%113 = load i32, i32* %17
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %116
115: ; preds = %112
br label %102
116: ; preds = %112
br label %117
117: ; preds = %116
%118 = load i32, i32* %13
%119 = call i64 @FD_ISSET(i32 %118, i32* %15)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %145
121: ; preds = %117
%122 = load i32, i32* %13
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%124 = call i32 @read(i32 %122, i8* %123, i32 1)
store i32 %124, i32* %18
%125 = load i32, i32* %18
%126 = icmp eq i32 %125, 0
br i1 %126, label %127, label %128
127: ; preds = %121
br label %161
128: ; preds = %121
%129 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%130 = load i8, i8* %129
%131 = sext i8 %130 to i32
switch i32 %131, label %141 [
i32 111, label %132
i32 101, label %135
i32 114, label %138
]
132: ; preds = %128
%133 = load i32, i32* %13
%134 = call i32 @do_msg(i32 %133, i32 1)
br label %144
135: ; preds = %128
%136 = load i32, i32* %13
%137 = call i32 @do_msg(i32 %136, i32 2)
br label %144
138: ; preds = %128
%139 = load i32, i32* %13
%140 = call i32 @do_return_msg(i32 %139)
store i32 %140, i32* %3
br label %164
141: ; preds = %128
%142 = load i32, i32* @stderr
%143 = call i32 @fprintf(i32 %142, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %164
144: ; preds = %135, %132
br label %145
145: ; preds = %144, %117
%146 = call i64 @FD_ISSET(i32 0, i32* %15)
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %160
148: ; preds = %145
%149 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%150 = call i32 @read(i32 0, i8* %149, i32 1024)
store i32 %150, i32* %18
%151 = load i32, i32* %13
%152 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%153 = load i32, i32* %18
%154 = call i32 @write(i32 %151, i8* %152, i32 %153)
%155 = call i32 @fflush(i32* null)
%156 = load i32, i32* %18
%157 = icmp eq i32 %156, 0
br i1 %157, label %158, label %159
158: ; preds = %148
br label %161
159: ; preds = %148
br label %160
160: ; preds = %159, %145
br label %102
161: ; preds = %158, %127, %111
%162 = load i32, i32* %13
%163 = call i32 @close(i32 %162)
store i32 0, i32* %3
br label %164
164: ; preds = %161, %141, %138, %21
%165 = load i32, i32* %3
ret i32 %165
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"socket needed\0A\00"
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@AF_LOCAL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [5 x i8] c"%06x\00"
@FD_SETSIZE = global i32 0
@.str.2 = [17 x i8] c"Protocol error.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_un
%6 = alloca i32
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %105
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = bitcast %struct.sockaddr_un* %5 to i8*
%17 = bitcast i32* %6 to i8*
%18 = load i32, i32* @PF_LOCAL
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* @AF_LOCAL
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %21, i32* %22
%23 = tail call i32 @strcpy(i32 undef, i8* %13)
%24 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%25 = call i32 @SUN_LEN(%struct.sockaddr_un* %5)
%26 = call i32 @connect(i32 %20, %struct.sockaddr* %24, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %11
%29 = load i8*, i8** %1
%30 = call i32 @perror(i8* %29)
br label %31
31: ; preds = %28, %11
%32 = load i32, i32* @F_GETFL
%33 = call i32 @fcntl(i32 %20, i32 %32, i32 0)
%34 = load i32, i32* @F_GETFL
%35 = load i32, i32* @O_NONBLOCK
%36 = or i32 %35, %33
%37 = call i32 @fcntl(i32 %20, i32 %34, i32 %36)
%38 = load i32, i32* @F_GETFL
%39 = call i32 @fcntl(i32 0, i32 %38, i32 0)
%40 = load i32, i32* @F_GETFL
%41 = load i32, i32* @O_NONBLOCK
%42 = or i32 %41, %39
%43 = call i32 @fcntl(i32 0, i32 %40, i32 %42)
%44 = add nsw i32 %0, -2
%45 = sext i32 %44 to i64
%46 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %45)
%47 = call i32 @write(i32 %20, i8* %14, i32 6)
%48 = icmp sgt i32 %0, 2
br i1 %48, label %49, label %63
49: ; preds = %31
%50 = zext i32 %0 to i64
br label %51
51: ; preds = %49, %51
%52 = phi i64 [ 2, %49 ], [ %61, %51 ]
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = call i64 @strlen(i8* dereferenceable(1) %54)
%56 = call i64 @strlen_utf8(i8* %54)
%57 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %56)
%58 = call i32 @write(i32 %20, i8* %14, i32 6)
%59 = trunc i64 %55 to i32
%60 = call i32 @write(i32 %20, i8* %54, i32 %59)
%61 = add nuw nsw i64 %52, 1
%62 = icmp eq i64 %61, %50
br i1 %62, label %63, label %51
63: ; preds = %51, %31
%64 = call i32 @fflush(i32* null)
br label %65
65: ; preds = %95, %63
%66 = call i32 @FD_ZERO(i32* %6)
%67 = call i32 @FD_SET(i32 0, i32* %6)
%68 = call i32 @FD_SET(i32 %20, i32* %6)
%69 = load i32, i32* @FD_SETSIZE
%70 = call i32 @select(i32 %69, i32* %6, i32* null, i32* null, i32* null)
%71 = icmp slt i32 %70, 0
br i1 %71, label %101, label %72
72: ; preds = %65
%73 = icmp eq i32 %70, 0
br i1 %73, label %95, label %74
74: ; preds = %72
%75 = call i64 @FD_ISSET(i32 %20, i32* %6)
%76 = icmp eq i64 %75, 0
br i1 %76, label %92, label %77
77: ; preds = %74
%78 = call i32 @read(i32 %20, i8* %15, i32 1)
%79 = icmp eq i32 %78, 0
br i1 %79, label %101, label %80
80: ; preds = %77
%81 = load i8, i8* %15
%82 = sext i8 %81 to i32
switch i32 %82, label %86 [
i32 111, label %89
i32 101, label %83
i32 114, label %84
]
83: ; preds = %80
br label %89
84: ; preds = %80
%85 = call i32 @do_return_msg(i32 %20)
br label %103
86: ; preds = %80
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %103
89: ; preds = %80, %83
%90 = phi i32 [ 2, %83 ], [ 1, %80 ]
%91 = call i32 @do_msg(i32 %20, i32 %90)
br label %92
92: ; preds = %89, %74
%93 = call i64 @FD_ISSET(i32 0, i32* %6)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %96
95: ; preds = %92, %96, %72
br label %65
96: ; preds = %92
%97 = call i32 @read(i32 0, i8* %15, i32 1024)
%98 = call i32 @write(i32 %20, i8* %15, i32 %97)
%99 = call i32 @fflush(i32* null)
%100 = icmp eq i32 %97, 0
br i1 %100, label %101, label %95
101: ; preds = %96, %77, %65
%102 = call i32 @close(i32 %20)
br label %103
103: ; preds = %101, %86, %84
%104 = phi i32 [ 0, %101 ], [ -1, %86 ], [ %85, %84 ]
br label %105
105: ; preds = %103, %8
%106 = phi i32 [ 1, %8 ], [ %104, %103 ]
ret i32 %106
}