#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char *);
int receive_fd(int);
int sock_dgram(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void run(char *path, char *string) {
  int fd = sock_dgram(path);
  if (fd == -1) {
    perror("sock_dgram");
    return;
  }
  for (;;) {
    int connfd = receive_fd(fd);
    if (connfd == -1) {
      close(fd);
      return;
    }
    write(connfd, string, strlen(string));
    close(connfd);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <sock_dgram@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1197 <run+0x37>
lea    0xe73(%rip),%rdi
call   1080 <perror@plt>
jmp    11f0 <run+0x90>
jmp    119c <run+0x3c>
mov    -0x14(%rbp),%edi
call   1060 <receive_fd@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11be <run+0x5e>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11f0 <run+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
jmp    119c <run+0x3c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1070 <sock_dgram@plt>
cmp    $0xffffffff,%eax
je     11c6 <run+0x66>
mov    %eax,%r14d
mov    %eax,%edi
call   1060 <receive_fd@plt>
cmp    $0xffffffff,%eax
je     11ba <run+0x5a>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1060 <receive_fd@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1190 <run+0x30>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>
lea    0xe33(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"sock_dgram\00"
define void @run(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @sock_dgram(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %30
13: ; preds = %2
br label %14
14: ; preds = %22, %13
%15 = load i32, i32* %5
%16 = call i32 @receive_fd(i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
br label %30
22: ; preds = %14
%23 = load i32, i32* %6
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
br label %14
30: ; preds = %19, %11
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"sock_dgram\00"
define void @run(i8* %0, i8* %1) {
%3 = tail call i32 @sock_dgram(i8* %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @receive_fd(i32 %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %19
10: ; preds = %12, %5
%11 = tail call i32 @close(i32 %3)
br label %19
12: ; preds = %5, %12
%13 = phi i32 [ %17, %12 ], [ %6, %5 ]
%14 = tail call i32 @strlen(i8* %1)
%15 = tail call i32 @write(i32 %13, i8* %1, i32 %14)
%16 = tail call i32 @close(i32 %13)
%17 = tail call i32 @receive_fd(i32 %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %10, label %12
19: ; preds = %10, %8
ret void
}