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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ SOCK_STREAM;
int SUN_LEN(struct sockaddr_un *);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usleep(int);
int main(void) {
  char str[100];
  int socket_desc;
  struct sockaddr_un remote;
  if ((socket_desc = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  fcntl(socket_desc, F_SETFD, fcntl(socket_desc, F_GETFD) | FD_CLOEXEC);
  remote.sun_family = AF_UNIX;
  strcpy(remote.sun_path, "kmotionsocket");
  printf("Trying to connect...\n");
  int len;
  len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (connect(socket_desc, (struct sockaddr *)&remote, len) == -1) {
    perror("connect failed launching server");
    char cwd[1024];
    if (getcwd(cwd, sizeof(cwd)) != NULL) {
      fprintf(stdout, "Current working dir: %s\n", cwd);
    } else {
      perror("getcwd() error");
      exit(1);
    }
    char command[1024];
    sprintf(command, "%s/%s", cwd, "KMotionServer");
    system(command);
    int i;
    for (i = 0; i < 100; i++) {
      if (connect(socket_desc, (struct sockaddr *)&remote, SUN_LEN(&remote)) ==
          -1) {
        perror("connect");
      } else {
        break;
      }
      usleep(50 * 1000);
    }
    if (i == 100) {
      exit(1);
    }
  }
  printf("Connected.\n");
  int t;
  while (printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
    if (strncmp(str, "exit", 4) == 0) {
      close(socket_desc);
      _exit(0);
      break;
    }
    if (send(socket_desc, str, strlen(str), 0) == -1) {
      perror("send");
      exit(1);
    }
    if ((t = recv(socket_desc, str, 100, 0)) > 0) {
      str[t] = '\0';
      printf("echo> %s", str);
    } else {
      if (t < 0)
        perror("recv");
      else
        printf("Server closed connection\n");
      exit(1);
    }
  }
  close(socket_desc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x74(%rbp)
cmp    $0xffffffff,%eax
jne    129d <main+0x4d>
lea    0xd79(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8a0(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x89c(%rbp)
mov    -0x74(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <fcntl@plt>
mov    -0x8a0(%rbp),%edi
mov    -0x89c(%rbp),%esi
mov    %eax,%edx
mov    0x2ce3(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <fcntl@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    -0x88(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   1060 <strcpy@plt>
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x88(%rbp),%rdi
call   1080 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x8c(%rbp)
mov    -0x74(%rbp),%edi
lea    -0x88(%rbp),%rsi
mov    -0x8c(%rbp),%edx
call   1140 <connect@plt>
cmp    $0xffffffff,%eax
jne    147b <main+0x22b>
lea    0xcd4(%rip),%rdi
call   1110 <perror@plt>
lea    -0x490(%rbp),%rdi
mov    $0x400,%esi
call   10c0 <getcwd@plt>
cmp    $0x0,%rax
je     1391 <main+0x141>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
lea    -0x490(%rbp),%rdx
lea    0xcbd(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    13a7 <main+0x157>
lea    0xcc5(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x890(%rbp),%rdi
lea    -0x490(%rbp),%rdx
lea    0xcb0(%rip),%rsi
lea    0xcaf(%rip),%rcx
call   1120 <sprintf@plt>
lea    -0x890(%rbp),%rdi
call   1090 <system@plt>
movl   $0x0,-0x894(%rbp)
cmpl   $0x64,-0x894(%rbp)
jge    145f <main+0x20f>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8ac(%rbp)
lea    -0x88(%rbp),%rax
mov    %rax,-0x8a8(%rbp)
lea    -0x88(%rbp),%rdi
call   1150 <SUN_LEN@plt>
mov    -0x8ac(%rbp),%edi
mov    -0x8a8(%rbp),%rsi
mov    %eax,%edx
call   1140 <connect@plt>
cmp    $0xffffffff,%eax
jne    143c <main+0x1ec>
lea    0xc4e(%rip),%rdi
call   1110 <perror@plt>
jmp    1441 <main+0x1f1>
jmp    145f <main+0x20f>
mov    $0xc350,%edi
call   1160 <usleep@plt>
mov    -0x894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x894(%rbp)
jmp    13de <main+0x18e>
cmpl   $0x64,-0x894(%rbp)
jne    1476 <main+0x226>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    147b <main+0x22b>
lea    0xc06(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    0xc04(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2b3e(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10e0 <fgets@plt>
mov    0x2b2b(%rip),%rax
mov    (%rax),%edi
call   1100 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14d1 <main+0x281>
jmp    15d1 <main+0x381>
lea    -0x70(%rbp),%rdi
lea    0xbbb(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    14ff <main+0x2af>
mov    -0x74(%rbp),%edi
call   10d0 <close@plt>
xor    %edi,%edi
call   1050 <_exit@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8bc(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x8b8(%rbp)
lea    -0x70(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x8bc(%rbp),%edi
mov    -0x8b8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
cmp    $0xffffffff,%eax
jne    1551 <main+0x301>
lea    0xb5a(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x74(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x898(%rbp)
cmp    $0x0,%eax
jle    1596 <main+0x346>
movslq -0x898(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xb17(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    15cc <main+0x37c>
cmpl   $0x0,-0x898(%rbp)
jge    15b4 <main+0x364>
lea    0xb00(%rip),%rdi
call   1110 <perror@plt>
jmp    15c2 <main+0x372>
lea    0xaf4(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1489 <main+0x239>
mov    -0x74(%rbp),%edi
call   10d0 <close@plt>
xor    %eax,%eax
add    $0x8c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    0x2d70(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
cmp    $0xffffffff,%eax
je     1505 <main+0x2a5>
mov    %eax,%r13d
mov    0x2d32(%rip),%rax
mov    (%rax),%ebx
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
xor    %eax,%eax
call   1080 <fcntl@plt>
mov    0x2d06(%rip),%rcx
or     (%rcx),%eax
mov    %r13d,%edi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fcntl@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0xd28(%rip),%rsi
call   1060 <strcpy@plt>
lea    0xda9(%rip),%rdi
call   1070 <puts@plt>
call   1090 <strlen@plt>
lea    0x4(%rax),%edx
mov    %rsp,%rsi
mov    %r13d,%edi
call   1150 <connect@plt>
cmp    $0xffffffff,%eax
je     141d <main+0x1bd>
lea    0xd96(%rip),%rdi
call   1070 <puts@plt>
lea    0xd5a(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    0x2cba(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   10f0 <fgets@plt>
mov    0x0(%rbp),%edi
call   1110 <feof@plt>
test   %eax,%eax
jne    1401 <main+0x1a1>
lea    0xd26(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xd24(%rip),%r15
lea    0xd10(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     14d5 <main+0x275>
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10b0 <send@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x284>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14ed <main+0x28d>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10f0 <fgets@plt>
mov    0x0(%rbp),%edi
call   1110 <feof@plt>
test   %eax,%eax
je     1370 <main+0x110>
mov    %r13d,%edi
call   10e0 <close@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbea(%rip),%rdi
call   1120 <perror@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   10d0 <getcwd@plt>
test   %rax,%rax
je     150e <main+0x2ae>
mov    0x2b68(%rip),%rax
mov    (%rax),%edi
lea    0xbdd(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1100 <fprintf@plt>
lea    0xbf1(%rip),%rsi
lea    0xbf0(%rip),%rcx
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1130 <sprintf@plt>
mov    %rbx,%rdi
call   10a0 <system@plt>
mov    $0x64,%ebp
mov    %rsp,%rbx
lea    0xbd4(%rip),%r14
mov    %rbx,%rdi
call   1160 <SUN_LEN@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1150 <connect@plt>
cmp    $0xffffffff,%eax
jne    1305 <main+0xa5>
mov    %r14,%rdi
call   1120 <perror@plt>
mov    $0xc350,%edi
call   1170 <usleep@plt>
add    $0xffffffff,%ebp
jne    1496 <main+0x236>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    %r13d,%edi
call   10e0 <close@plt>
xor    %edi,%edi
call   1050 <_exit@plt>
lea    0xb8f(%rip),%rdi
jmp    14f6 <main+0x296>
jns    1517 <main+0x2b7>
lea    0xb92(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    0xafb(%rip),%rdi
jmp    14f6 <main+0x296>
lea    0xb32(%rip),%rdi
jmp    14f6 <main+0x296>
lea    0xb8f(%rip),%rdi
call   1070 <puts@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@F_SETFD = global i32 0
@F_GETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"kmotionsocket\00"
@.str.2 = [22 x i8] c"Trying to connect...\0A\00"
@.str.3 = [32 x i8] c"connect failed launching server\00"
@stdout = global i32 0
@.str.4 = [25 x i8] c"Current working dir: %s\0A\00"
@.str.5 = [15 x i8] c"getcwd() error\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [14 x i8] c"KMotionServer\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.9 = [12 x i8] c"Connected.\0A\00"
@.str.10 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.11 = [5 x i8] c"exit\00"
@.str.12 = [5 x i8] c"send\00"
@.str.13 = [9 x i8] c"echo> %s\00"
@.str.14 = [5 x i8] c"recv\00"
@.str.15 = [26 x i8] c"Server closed connection\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %3
%19 = load i32, i32* @F_SETFD
%20 = load i32, i32* %3
%21 = load i32, i32* @F_GETFD
%22 = call i32 (i32, i32, ...) @fcntl(i32 %20, i32 %21)
%23 = load i32, i32* @FD_CLOEXEC
%24 = or i32 %22, %23
%25 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19, i32 %24)
%26 = load i32, i32* @AF_UNIX
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%31 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = add i64 %35, 4
%37 = trunc i64 %36 to i32
store i32 %37, i32* %5
%38 = load i32, i32* %3
%39 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%40 = load i32, i32* %5
%41 = call i32 @connect(i32 %38, %struct.sockaddr* %39, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %84
43: ; preds = %17
%44 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = call i32* @getcwd(i8* %45, i32 1024)
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32, i32* @stdout
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %50)
br label %55
52: ; preds = %43
%53 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %57, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%60 = call i32 @system(i8* %59)
store i32 0, i32* %8
br label %61
61: ; preds = %75, %55
%62 = load i32, i32* %8
%63 = icmp slt i32 %62, 100
br i1 %63, label %64, label %78
64: ; preds = %61
%65 = load i32, i32* %3
%66 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%67 = call i32 @SUN_LEN(%struct.sockaddr_un* %4)
%68 = call i32 @connect(i32 %65, %struct.sockaddr* %66, i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %73
72: ; preds = %64
br label %78
73: ; preds = %70
%74 = call i32 @usleep(i32 50000)
br label %75
75: ; preds = %73
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %61
78: ; preds = %72, %61
%79 = load i32, i32* %8
%80 = icmp eq i32 %79, 100
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %78
br label %84
84: ; preds = %83, %17
%85 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %133, %84
%87 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%89 = load i32, i32* @stdin
%90 = call i32 @fgets(i8* %88, i32 100, i32 %89)
%91 = load i32, i32* @stdin
%92 = call i32 @feof(i32 %91)
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br i1 %94, label %95, label %134
95: ; preds = %86
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%97 = call i64 @strncmp(i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = load i32, i32* %3
%101 = call i32 @close(i32 %100)
%102 = call i32 @_exit(i32 0)
unreachable
103: ; preds = %95
%104 = load i32, i32* %3
%105 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%106 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%107 = call i32 @strlen(i8* %106)
%108 = call i32 @send(i32 %104, i8* %105, i32 %107, i32 0)
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %103
%111 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %103
%114 = load i32, i32* %3
%115 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%116 = call i32 @recv(i32 %114, i8* %115, i32 100, i32 0)
store i32 %116, i32* %9
%117 = icmp sgt i32 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %113
%119 = load i32, i32* %9
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %120
store i8 0, i8* %121
%122 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%123 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i8* %122)
br label %133
124: ; preds = %113
%125 = load i32, i32* %9
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %124
%128 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %131
129: ; preds = %124
%130 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i64 0, i64 0))
br label %131
131: ; preds = %129, %127
%132 = call i32 @exit(i32 1)
unreachable
133: ; preds = %118
br label %86
134: ; preds = %86
%135 = load i32, i32* %3
%136 = call i32 @close(i32 %135)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@F_SETFD = global i32 0
@F_GETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"kmotionsocket\00"
@.str.3 = [32 x i8] c"connect failed launching server\00"
@stdout = global i32 0
@.str.4 = [25 x i8] c"Current working dir: %s\0A\00"
@.str.5 = [15 x i8] c"getcwd() error\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [14 x i8] c"KMotionServer\00"
@.str.8 = [8 x i8] c"connect\00"
@.str.10 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.11 = [5 x i8] c"exit\00"
@.str.12 = [5 x i8] c"send\00"
@.str.13 = [9 x i8] c"echo> %s\00"
@.str.14 = [5 x i8] c"recv\00"
@str = [21 x i8] c"Trying to connect...\00"
@str.16 = [11 x i8] c"Connected.\00"
@str.17 = [25 x i8] c"Server closed connection\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca %struct.sockaddr_un
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.sockaddr_un* %2 to i8*
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @F_SETFD
%16 = load i32, i32* @F_GETFD
%17 = tail call i32 (i32, i32, ...) @fcntl(i32 %9, i32 %16)
%18 = load i32, i32* @FD_CLOEXEC
%19 = or i32 %18, %17
%20 = tail call i32 (i32, i32, ...) @fcntl(i32 %9, i32 %15, i32 %19)
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %21, i32* %22
%23 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @strlen(i8* undef)
%26 = add i32 %25, 4
%27 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%28 = call i32 @connect(i32 %9, %struct.sockaddr* %27, i32 %26)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %57
30: ; preds = %14
%31 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%33 = call i32* @getcwd(i8* %32, i32 1024)
%34 = icmp eq i32* %33, null
br i1 %34, label %41, label %35
35: ; preds = %30
%36 = load i32, i32* @stdout
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%39 = call i32 @sprintf(i8* %38, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 @system(i8* %38)
br label %44
41: ; preds = %30
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35, %49
%45 = phi i32 [ 0, %35 ], [ %52, %49 ]
%46 = call i32 @SUN_LEN(%struct.sockaddr_un* %2)
%47 = call i32 @connect(i32 %9, %struct.sockaddr* %27, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %56
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%51 = call i32 @usleep(i32 50000)
%52 = add nuw nsw i32 %45, 1
%53 = icmp eq i32 %52, 100
br i1 %53, label %54, label %44
54: ; preds = %49
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %44
br label %57
57: ; preds = %56, %14
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
%59 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%60 = load i32, i32* @stdin
%61 = call i32 @fgets(i8* %5, i32 100, i32 %60)
%62 = load i32, i32* @stdin
%63 = call i32 @feof(i32 %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %99
65: ; preds = %57, %81
%66 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = call i32 @close(i32 %9)
%70 = call i32 @_exit(i32 0)
unreachable
71: ; preds = %65
%72 = call i32 @strlen(i8* %5)
%73 = call i32 @send(i32 %9, i8* %5, i32 %72, i32 0)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = call i32 @recv(i32 %9, i8* %5, i32 100, i32 0)
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %91
81: ; preds = %78
%82 = zext i32 %79 to i64
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %82
store i8 0, i8* %83
%84 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i8* %5)
%85 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%86 = load i32, i32* @stdin
%87 = call i32 @fgets(i8* %5, i32 100, i32 %86)
%88 = load i32, i32* @stdin
%89 = call i32 @feof(i32 %88)
%90 = icmp eq i32 %89, 0
br i1 %90, label %65, label %99
91: ; preds = %78
%92 = icmp slt i32 %79, 0
br i1 %92, label %93, label %95
93: ; preds = %91
%94 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %97
95: ; preds = %91
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
br label %97
97: ; preds = %95, %93
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %81, %57
%100 = call i32 @close(i32 %9)
ret i32 0
}