#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendFunc(int, char *);
int /*<<< orphan*/ stdin;
void dump_unix(int sock_fd) {
  char tmp[1024] = {0};
  while (fgets(tmp, 1024, stdin) != NULL) {
    sendFunc(sock_fd, tmp);
    memset(tmp, 0, 1024);
  }
}


x86 assembly (clang, -O0):
<dump_unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     119c <dump_unix+0x6c>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1050 <sendFunc@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
jmp    1151 <dump_unix+0x21>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_unix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x2e92(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     119e <dump_unix+0x6e>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <sendFunc@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jne    1170 <dump_unix+0x40>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define void @dump_unix(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 %0, i32* %2
%4 = bitcast [1024 x i8]* %3 to i8*
br label %5
5: ; preds = %10, %1
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 1024, i32 %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i32, i32* %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @sendFunc(i32 %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 1024)
br label %5
16: ; preds = %5
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
define void @dump_unix(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %3, i32 1024, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1, %7
%8 = call i32 @sendFunc(i32 %0, i8* %3)
%9 = call i32 @memset(i8* %3, i32 0, i32 1024)
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %3, i32 1024, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %7
13: ; preds = %7, %1
ret void
}