#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 inotify_event {
  scalar_t__ len;
  int /*<<< orphan*/ name;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ evbuf;

/* Variables and functions */
int /*<<< orphan*/ IN_CLOSE_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ free(char *);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
char *join_path(char *, char *);
int open_link(char *, char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ send_file(int, char *);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
void transmit(char **args) {
  int inotify_fd;
  inotify_fd = inotify_init();
  if (inotify_fd == -1)
    err(1, "inotify_init");
  int watch_fd;
  watch_fd = inotify_add_watch(inotify_fd, args[0], IN_CLOSE_WRITE);
  if (watch_fd == -1)
    err(1, "inotify_add_watch");
  int sock;
  sock = open_link(args[2], args[3]);
  if (sock == -1)
    err(1, "failed to connect to receiver");
  puts("connected to receiver");
  char *path;
  path = join_path(args[0], args[1]);
  char evbuf[(sizeof(struct inotify_event) + 16) * 50];
  for (;;) {
    ssize_t len;
    len = read(inotify_fd, evbuf, sizeof(evbuf));
    if (len < 0)
      err(1, "inotify error");
    ssize_t proc;
    proc = 0;
    while (proc < len) {
      struct inotify_event *ev;
      ev = (struct inotify_event *)&evbuf[proc];
      if (ev->len && strcmp(args[1], ev->name) == 0)
        send_file(sock, path);
      proc += ev->len + sizeof(*ev);
    }
  }
  free(path);
  close(sock);
}


x86 assembly (clang, -O0):
<transmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <inotify_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c4 <transmit+0x34>
mov    $0x1,%edi
lea    0xe41(%rip),%rsi
call   1080 <err@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
call   1090 <inotify_add_watch@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11fa <transmit+0x6a>
mov    $0x1,%edi
lea    0xe18(%rip),%rsi
call   1080 <err@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rsi
call   10b0 <open_link@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122d <transmit+0x9d>
mov    $0x1,%edi
lea    0xdf7(%rip),%rsi
call   1080 <err@plt>
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <join_path@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x660(%rbp),%rsi
mov    $0x640,%edx
call   1050 <read@plt>
mov    %rax,-0x668(%rbp)
cmpq   $0x0,-0x668(%rbp)
jge    128b <transmit+0xfb>
mov    $0x1,%edi
lea    0xdcd(%rip),%rsi
call   1080 <err@plt>
movq   $0x0,-0x670(%rbp)
mov    -0x670(%rbp),%rax
cmp    -0x668(%rbp),%rax
jge    131e <transmit+0x18e>
lea    -0x660(%rbp),%rax
add    -0x670(%rbp),%rax
mov    %rax,-0x678(%rbp)
mov    -0x678(%rbp),%rax
cmpq   $0x0,(%rax)
je     12fd <transmit+0x16d>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x678(%rbp),%rax
mov    0x8(%rax),%esi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12fd <transmit+0x16d>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10a0 <send_file@plt>
mov    -0x678(%rbp),%rax
mov    (%rax),%rax
add    $0x10,%rax
add    -0x670(%rbp),%rax
mov    %rax,-0x670(%rbp)
jmp    1296 <transmit+0x106>
jmp    1251 <transmit+0xc1>

x86 assembly (clang, -O2):
<transmit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x658,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <inotify_init@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11c3 <transmit+0x33>
lea    0xe47(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    (%rbx),%rsi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1090 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    11ec <transmit+0x5c>
lea    0xe2b(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %ebp,0xc(%rsp)
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rsi
call   10b0 <open_link@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    1216 <transmit+0x86>
lea    0xe13(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
call   1040 <join_path@plt>
mov    %rax,%rbp
jmp    1251 <transmit+0xc1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
lea    0xe07(%rip),%rsi
call   1080 <err@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x640,%edx
call   1050 <read@plt>
test   %rax,%rax
js     1240 <transmit+0xb0>
je     1251 <transmit+0xc1>
mov    %rax,%r13
xor    %r12d,%r12d
jmp    128c <transmit+0xfc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r14,%r12
add    $0x10,%r12
cmp    %r13,%r12
jge    1251 <transmit+0xc1>
mov    0x10(%rsp,%r12,1),%r14
test   %r14,%r14
je     1280 <transmit+0xf0>
mov    0x8(%rbx),%rdi
mov    0x18(%rsp,%r12,1),%esi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1280 <transmit+0xf0>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10a0 <send_file@plt>
jmp    1280 <transmit+0xf0>

LLVM IR (-O0):
%struct.inotify_event = type { i64, i32 }
@.str = [13 x i8] c"inotify_init\00"
@IN_CLOSE_WRITE = global i32 0
@.str.1 = [18 x i8] c"inotify_add_watch\00"
@.str.2 = [30 x i8] c"failed to connect to receiver\00"
@.str.3 = [22 x i8] c"connected to receiver\00"
@.str.4 = [14 x i8] c"inotify error\00"
define void @transmit(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [1600 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.inotify_event*
store i8** %0, i8*** %2
%11 = call i32 (...) @inotify_init()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i32, i32* %3
%18 = load i8**, i8*** %2
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* @IN_CLOSE_WRITE
%22 = call i32 @inotify_add_watch(i32 %17, i8* %20, i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %16
%28 = load i8**, i8*** %2
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %2
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @open_link(i8* %30, i8* %33)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %27
%40 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8**, i8*** %2
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %2
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i8* @join_path(i8* %43, i8* %46)
store i8* %47, i8** %6
br label %48
48: ; preds = %89, %39
%49 = load i32, i32* %3
%50 = getelementptr inbounds [1600 x i8], [1600 x i8]* %7, i64 0, i64 0
%51 = call i64 @read(i32 %49, i8* %50, i32 1600)
store i64 %51, i64* %8
%52 = load i64, i64* %8
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
store i64 0, i64* %9
br label %57
57: ; preds = %82, %56
%58 = load i64, i64* %9
%59 = load i64, i64* %8
%60 = icmp slt i64 %58, %59
br i1 %60, label %61, label %89
61: ; preds = %57
%62 = load i64, i64* %9
%63 = getelementptr inbounds [1600 x i8], [1600 x i8]* %7, i64 0, i64 %62
%64 = bitcast i8* %63 to %struct.inotify_event*
store %struct.inotify_event* %64, %struct.inotify_event** %10
%65 = load %struct.inotify_event*, %struct.inotify_event** %10
%66 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %82
69: ; preds = %61
%70 = load i8**, i8*** %2
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = load %struct.inotify_event*, %struct.inotify_event** %10
%74 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %73, i32 0, i32 1
%75 = load i32, i32* %74
%76 = call i64 @strcmp(i8* %72, i32 %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %69
%79 = load i32, i32* %5
%80 = load i8*, i8** %6
%81 = call i32 @send_file(i32 %79, i8* %80)
br label %82
82: ; preds = %78, %69, %61
%83 = load %struct.inotify_event*, %struct.inotify_event** %10
%84 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %83, i32 0, i32 0
%85 = load i64, i64* %84
%86 = add i64 %85, 16
%87 = load i64, i64* %9
%88 = add i64 %87, %86
store i64 %88, i64* %9
br label %57
89: ; preds = %57
br label %48
}

LLVM IR (-O2):
@.str = [13 x i8] c"inotify_init\00"
@IN_CLOSE_WRITE = global i32 0
@.str.1 = [18 x i8] c"inotify_add_watch\00"
@.str.2 = [30 x i8] c"failed to connect to receiver\00"
@.str.3 = [22 x i8] c"connected to receiver\00"
@.str.4 = [14 x i8] c"inotify error\00"
define void @transmit(i8** nocapture %0) {
%2 = alloca [1600 x i8]
%3 = tail call i32 (...) @inotify_init()
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = load i8*, i8** %0
%9 = load i32, i32* @IN_CLOSE_WRITE
%10 = tail call i32 @inotify_add_watch(i32 %3, i8* %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = getelementptr inbounds i8*, i8** %0, i64 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %0, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @open_link(i8* %16, i8* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%25 = load i8*, i8** %0
%26 = getelementptr inbounds i8*, i8** %0, i64 1
%27 = load i8*, i8** %26
%28 = tail call i8* @join_path(i8* %25, i8* %27)
%29 = getelementptr inbounds [1600 x i8], [1600 x i8]* %2, i64 0, i64 0
br label %30
30: ; preds = %35, %23
%31 = call i64 @read(i32 %3, i8* %29, i32 1600)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %53, %33, %36
br label %30
36: ; preds = %30
%37 = icmp eq i64 %31, 0
br i1 %37, label %35, label %38
38: ; preds = %36, %53
%39 = phi i64 [ %55, %53 ], [ 0, %36 ]
%40 = getelementptr inbounds [1600 x i8], [1600 x i8]* %2, i64 0, i64 %39
%41 = bitcast i8* %40 to i64*
%42 = load i64, i64* %41
%43 = icmp eq i64 %42, 0
br i1 %43, label %53, label %44
44: ; preds = %38
%45 = load i8*, i8** %26
%46 = getelementptr inbounds i8, i8* %40, i64 8
%47 = bitcast i8* %46 to i32*
%48 = load i32, i32* %47
%49 = tail call i64 @strcmp(i8* %45, i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = tail call i32 @send_file(i32 %19, i8* %28)
br label %53
53: ; preds = %51, %44, %38
%54 = add i64 %39, 16
%55 = add i64 %54, %42
%56 = icmp slt i64 %55, %31
br i1 %56, label %38, label %35
}