#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 netd_getMyID();
int netd_getSize();
int /*<<< orphan*/ netd_recvdat(int, char *, int);
int /*<<< orphan*/ netd_senddat(int, char *, int);
int /*<<< orphan*/ printf(char *, int, int, char *);
void worker() {
  int done;
  int my_id, from, to, size;
  char msg[200];
  my_id = netd_getMyID();
  size = netd_getSize();
  if (my_id == (size - 1))
    to = 0;
  else
    to = my_id + 1;
  from = my_id - 1;
  done = 0;
  while (!done) {
    netd_recvdat(from, msg, 200);
    if (msg[0] == '\1')
      done = 1;
    else
      printf("%d get message from %d:%s\n", my_id, from, msg);
    netd_senddat(to, msg, 200);
  }
}


x86 assembly (clang, -O0):
<worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    $0x0,%al
call   1060 <netd_getMyID@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <netd_getSize@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    118c <worker+0x3c>
movl   $0x0,-0x10(%rbp)
jmp    1195 <worker+0x45>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bb <worker+0x6b>
jmp    121d <worker+0xcd>
mov    -0xc(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xc8,%edx
call   1030 <netd_recvdat@plt>
movsbl -0xe0(%rbp),%eax
cmp    $0x1,%eax
jne    11eb <worker+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    1204 <worker+0xb4>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    -0xe0(%rbp),%rcx
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xc8,%edx
call   1050 <netd_senddat@plt>
jmp    11a5 <worker+0x55>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<worker>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd0,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <netd_getMyID@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <netd_getSize@plt>
add    $0xffffffff,%eax
lea    0x1(%r14),%r12d
cmp    %eax,%r14d
cmove  %ebx,%r12d
lea    -0x1(%r14),%ebx
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc8,%edx
call   1030 <netd_recvdat@plt>
cmpb   $0x1,(%rsp)
je     11e5 <worker+0x95>
lea    0xe60(%rip),%r15
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1040 <printf@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc8,%edx
call   1050 <netd_senddat@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc8,%edx
call   1030 <netd_recvdat@plt>
cmpb   $0x1,(%rsp)
jne    11b0 <worker+0x60>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0xc8,%edx
call   1050 <netd_senddat@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%d get message from %d:%s\0A\00"
define void @worker() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [200 x i8]
%7 = call i32 (...) @netd_getMyID()
store i32 %7, i32* %2
%8 = call i32 (...) @netd_getSize()
store i32 %8, i32* %5
%9 = load i32, i32* %2
%10 = load i32, i32* %5
%11 = sub nsw i32 %10, 1
%12 = icmp eq i32 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 0, i32* %4
br label %17
14: ; preds = %0
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %13
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %3
store i32 0, i32* %1
br label %20
20: ; preds = %38, %17
%21 = load i32, i32* %1
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load i32, i32* %3
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%27 = call i32 @netd_recvdat(i32 %25, i8* %26, i32 200)
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 1, i32* %1
br label %38
33: ; preds = %24
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35, i8* %36)
br label %38
38: ; preds = %33, %32
%39 = load i32, i32* %4
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%41 = call i32 @netd_senddat(i32 %39, i8* %40, i32 200)
br label %20
42: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"%d get message from %d:%s\0A\00"
define void @worker() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @netd_getMyID()
%4 = tail call i32 (...) @netd_getSize()
%5 = add nsw i32 %4, -1
%6 = icmp eq i32 %3, %5
%7 = add nsw i32 %3, 1
%8 = select i1 %6, i32 0, i32 %7
%9 = add nsw i32 %3, -1
%10 = call i32 @netd_recvdat(i32 %9, i8* %2, i32 200)
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 1
br i1 %12, label %19, label %13
13: ; preds = %0, %13
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %9, i8* %2)
%15 = call i32 @netd_senddat(i32 %8, i8* %2, i32 200)
%16 = call i32 @netd_recvdat(i32 %9, i8* %2, i32 200)
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 1
br i1 %18, label %19, label %13
19: ; preds = %13, %0
%20 = call i32 @netd_senddat(i32 %8, i8* %2, i32 200)
ret void
}