#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 /*<<< orphan*/ rbuf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
__attribute__((__unused__)) void pair_udp_send_char(int fds[], int num,
                                                    char payload) {
  char buf[100], rbuf[100];
  memset(buf, payload, sizeof(buf));
  while (num--) {
    if (write(fds[0], buf, sizeof(buf)) != sizeof(buf)) {
      fprintf(stderr, "ERROR: send failed left=%d\n", num);
      exit(1);
    }
    if (read(fds[1], rbuf, sizeof(rbuf)) != sizeof(rbuf)) {
      fprintf(stderr, "ERROR: recv failed left=%d\n", num);
      exit(1);
    }
    if (memcmp(buf, rbuf, sizeof(buf))) {
      fprintf(stderr, "ERROR: data failed left=%d\n", num);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<pair_udp_send_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0xd(%rbp),%al
movsbl %al,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     126d <pair_udp_send_char+0x10d>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1030 <write@plt>
cltq
cmp    $0x64,%rax
je     11e1 <pair_udp_send_char+0x81>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
cltq
cmp    $0x64,%rax
je     1227 <pair_udp_send_char+0xc7>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe04(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
mov    $0x64,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1268 <pair_udp_send_char+0x108>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xddf(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    118b <pair_udp_send_char+0x2b>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pair_udp_send_char>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x70(%rsp),%r15
mov    %r15,%rdi
mov    %edx,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
neg    %ebx
mov    %rsp,%r12
nopl   0x0(%rax)
test   %ebx,%ebx
je     11eb <pair_udp_send_char+0x8b>
mov    (%r14),%edi
mov    %r15,%rsi
mov    $0x64,%edx
call   1030 <write@plt>
cmp    $0x64,%eax
jne    120e <pair_udp_send_char+0xae>
mov    0x4(%r14),%edi
mov    %r12,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
cmp    $0x64,%eax
jne    11fa <pair_udp_send_char+0x9a>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x64,%edx
call   1060 <memcmp@plt>
add    $0x1,%ebx
test   %rax,%rax
je     1190 <pair_udp_send_char+0x30>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
neg    %ebx
lea    0xe4f(%rip),%rsi
jmp    1220 <pair_udp_send_char+0xc0>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
not    %ebx
lea    0xe10(%rip),%rsi
jmp    1220 <pair_udp_send_char+0xc0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
not    %ebx
lea    0xde0(%rip),%rsi
mov    %ebx,%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: send failed left=%d\0A\00"
@.str.1 = [28 x i8] c"ERROR: recv failed left=%d\0A\00"
@.str.2 = [28 x i8] c"ERROR: data failed left=%d\0A\00"
define void @pair_udp_send_char(i32* %0, i32 %1, i8 signext %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%10 = load i8, i8* %6
%11 = call i32 @memset(i8* %9, i8 signext %10, i32 100)
br label %12
12: ; preds = %52, %3
%13 = load i32, i32* %5
%14 = add nsw i32 %13, -1
store i32 %14, i32* %5
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 100)
%22 = sext i32 %21 to i64
%23 = icmp ne i64 %22, 100
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i32, i32* %5
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %16
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 100)
%35 = sext i32 %34 to i64
%36 = icmp ne i64 %35, 100
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i32, i32* %5
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %29
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%45 = call i64 @memcmp(i8* %43, i8* %44, i32 100)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* %5
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
br label %12
53: ; preds = %12
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: send failed left=%d\0A\00"
@.str.1 = [28 x i8] c"ERROR: recv failed left=%d\0A\00"
@.str.2 = [28 x i8] c"ERROR: data failed left=%d\0A\00"
define void @pair_udp_send_char(i32* nocapture %0, i32 %1, i8 signext %2) {
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %6, i8 signext %2, i32 100)
%9 = getelementptr inbounds i32, i32* %0, i64 1
br label %10
10: ; preds = %30, %3
%11 = phi i32 [ %1, %3 ], [ %12, %30 ]
%12 = add nsw i32 %11, -1
%13 = icmp eq i32 %11, 0
br i1 %13, label %37, label %14
14: ; preds = %10
%15 = load i32, i32* %0
%16 = call i32 @write(i32 %15, i8* %6, i32 100)
%17 = icmp eq i32 %16, 100
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %12)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* %9
%24 = call i32 @read(i32 %23, i8* %7, i32 100)
%25 = icmp eq i32 %24, 100
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = call i64 @memcmp(i8* %6, i8* %7, i32 100)
%32 = icmp eq i64 %31, 0
br i1 %32, label %10, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %10
ret void
}