#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 */
typedef int uint16_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sahn_cleanup();
int /*<<< orphan*/ sahn_init(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sahn_recv(int *, char *, int);
int /*<<< orphan*/ sahn_send(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: test1 <node-address>\n");
    exit(1);
  }
  uint16_t address = atoi(argv[1]), from;
  char *message = "Hello, world!";
  char buffer[64];
  sahn_init("examples/test2/nodes", address, NULL);
  if (address == 42) {
    sahn_send(19, message, strlen(message));
    sahn_recv(&from, buffer, 64);
    printf("Message from %d: %s\n", from, buffer);
  } else {
    sahn_recv(&from, buffer, 64);
    printf("Message from %d: %s\n", from, buffer);
    sahn_send(42, message, strlen(message));
  }
  sahn_cleanup();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x38>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe4e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sahn_init@plt>
cmpl   $0x2a,-0x14(%rbp)
jne    123d <main+0xbd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
mov    $0x13,%edi
call   1040 <sahn_send@plt>
lea    -0x60(%rbp),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x40,%edx
call   1060 <sahn_recv@plt>
mov    -0x18(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1285 <main+0x105>
lea    -0x60(%rbp),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x40,%edx
call   1060 <sahn_recv@plt>
mov    -0x18(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
mov    $0x2a,%edi
call   1040 <sahn_send@plt>
mov    $0x0,%al
call   1080 <sahn_cleanup@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
cmp    $0x2,%edi
jne    1263 <main+0xd3>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1030 <sahn_init@plt>
cmp    $0x2a,%ebx
jne    120a <main+0x7a>
lea    0xe3b(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    $0x13,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <sahn_send@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <sahn_recv@plt>
mov    0xc(%rsp),%esi
lea    0xe25(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1254 <main+0xc4>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <sahn_recv@plt>
mov    0xc(%rsp),%esi
lea    0xdf7(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdc3(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    $0x2a,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <sahn_send@plt>
xor    %eax,%eax
call   1090 <sahn_cleanup@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: test1 <node-address>\0A\00"
@.str.1 = [14 x i8] c"Hello, world!\00"
@.str.2 = [21 x i8] c"examples/test2/nodes\00"
@.str.3 = [21 x i8] c"Message from %d: %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 i8*
%9 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %8
%20 = load i32, i32* %6
%21 = call i32 @sahn_init(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32* null)
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 42
br i1 %23, label %24, label %34
24: ; preds = %15
%25 = load i8*, i8** %8
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @sahn_send(i32 19, i8* %25, i32 %27)
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%30 = call i32 @sahn_recv(i32* %7, i8* %29, i32 64)
%31 = load i32, i32* %7
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %31, i8* %32)
br label %44
34: ; preds = %15
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%36 = call i32 @sahn_recv(i32* %7, i8* %35, i32 64)
%37 = load i32, i32* %7
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %37, i8* %38)
%40 = load i8*, i8** %8
%41 = load i8*, i8** %8
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @sahn_send(i32 42, i8* %40, i32 %42)
br label %44
44: ; preds = %34, %24
%45 = call i32 (...) @sahn_cleanup()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Hello, world!\00"
@.str.2 = [21 x i8] c"examples/test2/nodes\00"
@.str.3 = [21 x i8] c"Message from %d: %s\0A\00"
@str = [28 x i8] c"Usage: test1 <node-address>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = bitcast i32* %3 to i8*
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%15 = tail call i32 @sahn_init(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32* null)
%16 = icmp eq i32 %12, 42
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @sahn_send(i32 19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @sahn_recv(i32* %3, i8* %14, i32 64)
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %14)
br label %29
23: ; preds = %9
%24 = call i32 @sahn_recv(i32* %3, i8* %14, i32 64)
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %14)
%27 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @sahn_send(i32 42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %23, %17
%30 = call i32 (...) @sahn_cleanup()
ret i32 0
}