#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*/ perror(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strlen(char *);
void joinChannel(const char *chan, int sockfd) {
  char output[1024] = {0};
  sprintf(output, "JOIN %s\r\n", chan);
  if (0 > send(sockfd, output, strlen(output), 0)) {
    perror("send error");
    pthread_exit(NULL);
  }
}


x86 assembly (clang, -O0):
<joinChannel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11f8 <joinChannel+0x98>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinChannel>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe76(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     11bd <joinChannel+0x5d>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
jmp    11b1 <joinChannel+0x51>

LLVM IR (-O0):
@.str = [10 x i8] c"JOIN %s\0D\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define void @joinChannel(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = bitcast [1024 x i8]* %5 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i64 @send(i32 %10, i8* %11, i32 %13, i32 0)
%15 = icmp sgt i64 0, %14
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @pthread_exit(i32* null)
br label %19
19: ; preds = %16, %2
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"JOIN %s\0D\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define void @joinChannel(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @strlen(i8* %4)
%7 = call i64 @send(i32 %1, i8* %4, i32 %6, i32 0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @pthread_exit(i32* null)
br label %12
12: ; preds = %9, %2
ret void
}