#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int strlen(char *);
void str_cli(FILE *fp, int sockfd) {
  int ret;
  char send_buf[4096];
  memset(send_buf, 0, 4096);
  while (fputs("msg: ", stdout) && fgets(send_buf, 4096, fp) != NULL) {
    if (strlen(send_buf) > 1) {
      send(sockfd, send_buf, strlen(send_buf), 0);
    }
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1050 <fputs@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1011(%rbp)
je     11d1 <str_cli+0x71>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1011(%rbp)
mov    -0x1011(%rbp),%al
test   $0x1,%al
jne    11e4 <str_cli+0x84>
jmp    1245 <str_cli+0xe5>
lea    -0x1010(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    1232 <str_cli+0xd2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1024(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1024(%rbp),%edi
mov    -0x1020(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1185 <str_cli+0x25>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    0x2e55(%rip),%rbx
mov    (%rbx),%esi
lea    0xe6c(%rip),%rdi
call   1050 <fputs@plt>
test   %rax,%rax
je     1201 <str_cli+0xa1>
mov    %rsp,%rbp
lea    0xe58(%rip),%r15
jmp    11c6 <str_cli+0x66>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%edi
call   1080 <fflush@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1050 <fputs@plt>
test   %rax,%rax
je     1201 <str_cli+0xa1>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1201 <str_cli+0xa1>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     11b0 <str_cli+0x50>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    11b0 <str_cli+0x50>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"msg: \00"
@stdout = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 4096)
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* @stdout
%11 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i32* @fgets(i8* %14, i32 4096, i32* %15)
%17 = icmp ne i32* %16, null
br label %18
18: ; preds = %13, %9
%19 = phi i1 [ false, %9 ], [ %17, %13 ]
br i1 %19, label %20, label %33
20: ; preds = %18
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* %4
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @send(i32 %25, i8* %26, i32 %28, i32 0)
br label %30
30: ; preds = %24, %20
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
br label %9
33: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"msg: \00"
@stdout = global i32 0
define void @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 4096)
%6 = load i32, i32* @stdout
%7 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %2, %18
%10 = call i32* @fgets(i8* %4, i32 4096, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = call i32 @strlen(i8* %4)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @strlen(i8* %4)
%17 = call i32 @send(i32 %1, i8* %4, i32 %16, i32 0)
br label %18
18: ; preds = %15, %12
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = load i32, i32* @stdout
%22 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %9, %18, %2
ret void
}