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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int dom_sock, i, w_ret, r_ret;
  struct sockaddr_un server;
  char buf[1024];
  for (i = 0; i < 2; i++) {
    dom_sock = socket(AF_UNIX, SOCK_STREAM, 0);
    if (dom_sock < 0) {
      printf("Error opening socket\n");
      return -1;
    }
    server.sun_family = AF_UNIX;
    strcpy(server.sun_path, "/var/run/clacks/"
                            "clacksid.sock");
    if (connect(dom_sock, (struct sockaddr *)&server,
                sizeof(struct sockaddr_un)) < 0) {
      printf("Error connecting to socket: %d\n", errno);
      return -1;
    }
    if (i % 2 == 0) {
      w_ret = write(dom_sock, "GET", sizeof("GET"));
    } else {
      w_ret = write(dom_sock, "TAG", sizeof("TAG"));
    }
    if (w_ret < 0) {
      printf("Error writing to socket\n");
      return -1;
    }
    r_ret = read(dom_sock, buf, sizeof(buf));
    if (r_ret < 0) {
      printf("Error reading from socket: %d\n", errno);
    } else {
      printf("Got uuid: %s\n", buf);
    }
    close(dom_sock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    1306 <main+0x196>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11da <main+0x6a>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    0xe26(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jge    1233 <main+0xc3>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1263 <main+0xf3>
mov    -0x14(%rbp),%edi
lea    0xe03(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    127a <main+0x10a>
mov    -0x14(%rbp),%edi
lea    0xdeb(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    129e <main+0x12e>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12db <main+0x16b>
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f0 <main+0x180>
lea    -0x430(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1190 <main+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2e55(%rip),%r14
mov    (%r14),%edi
mov    0x2e3b(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     12c2 <main+0x142>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
lea    0xe41(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     12cb <main+0x14b>
lea    0xe59(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
test   %eax,%eax
js     12e4 <main+0x164>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1223 <main+0xa3>
lea    0xe50(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    123a <main+0xba>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     12c2 <main+0x142>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xd9a(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     12cb <main+0x14b>
lea    0xdba(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
test   %eax,%eax
js     12e4 <main+0x164>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1302 <main+0x182>
lea    0xdb1(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1319 <main+0x199>
lea    0xdc2(%rip),%rdi
jmp    12eb <main+0x16b>
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
lea    0xd43(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12f0 <main+0x170>
lea    0xd88(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
lea    0xd34(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    12f5 <main+0x175>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error opening socket\0A\00"
@.str.1 = [30 x i8] c"/var/run/clacks/clacksid.sock\00"
@.str.2 = [32 x i8] c"Error connecting to socket: %d\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [4 x i8] c"TAG\00"
@.str.5 = [25 x i8] c"Error writing to socket\0A\00"
@.str.6 = [31 x i8] c"Error reading from socket: %d\0A\00"
@.str.7 = [14 x i8] c"Got uuid: %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 i32
%10 = alloca %struct.sockaddr_un
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %12
12: ; preds = %66, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %69
15: ; preds = %12
%16 = load i32, i32* @AF_UNIX
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
23: ; preds = %15
%24 = load i32, i32* @AF_UNIX
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @strcpy(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%31 = call i64 @connect(i32 %29, %struct.sockaddr* %30, i32 8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = load i32, i32* @errno
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %34)
store i32 -1, i32* %3
br label %70
36: ; preds = %23
%37 = load i32, i32* %7
%38 = srem i32 %37, 2
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %6
%42 = call i32 @write(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 4)
store i32 %42, i32* %8
br label %46
43: ; preds = %36
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 4)
store i32 %45, i32* %8
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %8
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
51: ; preds = %46
%52 = load i32, i32* %6
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 1024)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i32, i32* @errno
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %58)
br label %63
60: ; preds = %51
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %57
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
br label %66
66: ; preds = %63
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %12
69: ; preds = %12
store i32 0, i32* %3
br label %70
70: ; preds = %69, %49, %33, %21
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [30 x i8] c"/var/run/clacks/clacksid.sock\00"
@.str.2 = [32 x i8] c"Error connecting to socket: %d\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [4 x i8] c"TAG\00"
@.str.6 = [31 x i8] c"Error reading from socket: %d\0A\00"
@.str.7 = [14 x i8] c"Got uuid: %s\0A\00"
@str = [24 x i8] c"Error writing to socket\00"
@str.8 = [21 x i8] c"Error opening socket\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%9 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%10 = load i32, i32* @AF_UNIX
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %37, %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
br label %62
16: ; preds = %2
%17 = load i32, i32* @AF_UNIX
store i32 %17, i32* %7
%18 = call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%19 = call i64 @connect(i32 %12, %struct.sockaddr* %9, i32 8)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %43, %16
%22 = load i32, i32* @errno
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %62
24: ; preds = %16
%25 = call i32 @write(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 4)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %49, %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %62
29: ; preds = %24
%30 = call i32 @read(i32 %12, i8* %6, i32 1024)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %33)
br label %37
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %6)
br label %37
37: ; preds = %35, %32
%38 = call i32 @close(i32 %12)
%39 = load i32, i32* @AF_UNIX
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
%42 = icmp slt i32 %41, 0
br i1 %42, label %14, label %43
43: ; preds = %37
%44 = load i32, i32* @AF_UNIX
store i32 %44, i32* %7
%45 = load i32, i32* %8
%46 = call i32 @strcpy(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%47 = call i64 @connect(i32 %41, %struct.sockaddr* %9, i32 8)
%48 = icmp slt i64 %47, 0
br i1 %48, label %21, label %49
49: ; preds = %43
%50 = call i32 @write(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 4)
%51 = icmp slt i32 %50, 0
br i1 %51, label %27, label %52
52: ; preds = %49
%53 = call i32 @read(i32 %41, i8* %6, i32 1024)
%54 = icmp slt i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %6)
br label %60
57: ; preds = %52
%58 = load i32, i32* @errno
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %55
%61 = call i32 @close(i32 %41)
br label %62
62: ; preds = %60, %27, %21, %14
%63 = phi i32 [ -1, %14 ], [ -1, %21 ], [ -1, %27 ], [ 0, %60 ]
ret i32 %63
}