#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 connect_unix_dgram_socket(int, char *);
int create_unix_dgram_socket(char *, int /*<<< orphan*/);
int destroy_unix_socket(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int read(int, char *, int);
int write(int, char *, int);
int main(void) {
  int sfd, ret;
  char *string = "abcdefghijklmnopqrstuvwxyz";
  char buf[26];
  ret = sfd = create_unix_dgram_socket("/tmp/client", 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = connect_unix_dgram_socket(sfd, "/tmp/echosock");
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = write(sfd, string, 26);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = read(sfd, buf, 26);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  write(1, buf, 26);
  ret = destroy_unix_socket(sfd);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe8a(%rip),%rdi
xor    %esi,%esi
call   1030 <create_unix_dgram_socket@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b9 <main+0x49>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe64(%rip),%rsi
call   1060 <connect_unix_dgram_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e6 <main+0x76>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1a,%edx
call   1040 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1215 <main+0xa5>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1a,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1244 <main+0xd4>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x40(%rbp),%rsi
mov    $0x1,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <destroy_unix_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    127d <main+0x10d>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xe9f(%rip),%rdi
xor    %esi,%esi
call   1030 <create_unix_dgram_socket@plt>
test   %eax,%eax
js     11ea <main+0x7a>
mov    %eax,%ebx
lea    0xe97(%rip),%rsi
mov    %eax,%edi
call   1060 <connect_unix_dgram_socket@plt>
test   %eax,%eax
js     11ea <main+0x7a>
lea    0xe5e(%rip),%rsi
mov    %ebx,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
test   %eax,%eax
js     11ea <main+0x7a>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1a,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11ea <main+0x7a>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1070 <destroy_unix_socket@plt>
test   %eax,%eax
js     11ea <main+0x7a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [12 x i8] c"/tmp/client\00"
@.str.2 = [14 x i8] c"/tmp/echosock\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [26 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = call i32 @create_unix_dgram_socket(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %6, i32* %2
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i32 0)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @connect_unix_dgram_socket(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @perror(i32 0)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %2
%22 = load i8*, i8** %4
%23 = call i32 @write(i32 %21, i8* %22, i32 26)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i32 0)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i32, i32* %2
%31 = getelementptr inbounds [26 x i8], [26 x i8]* %5, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 26)
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = call i32 @perror(i32 0)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = getelementptr inbounds [26 x i8], [26 x i8]* %5, i64 0, i64 0
%40 = call i32 @write(i32 1, i8* %39, i32 26)
%41 = load i32, i32* %2
%42 = call i32 @destroy_unix_socket(i32 %41)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i32 0)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str.1 = [12 x i8] c"/tmp/client\00"
@.str.2 = [14 x i8] c"/tmp/echosock\00"
define i32 @main() {
%1 = alloca [26 x i8]
%2 = getelementptr inbounds [26 x i8], [26 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @create_unix_dgram_socket(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i32 0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @connect_unix_dgram_socket(i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i32 0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 26)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @perror(i32 0)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = call i32 @read(i32 %3, i8* %2, i32 26)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @perror(i32 0)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = call i32 @write(i32 1, i8* %2, i32 26)
%28 = tail call i32 @destroy_unix_socket(i32 %3)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = tail call i32 @perror(i32 0)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26
ret i32 0
}