#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write(int, char *, int);
void *writer(void *args) {
  char buf[1024];
  int n, sfd = *(int *)args;
  while (1) {
    fgets(buf, 1024, stdin);
    write(sfd, buf, 1024);
    if (atoi(buf) == -1) {
      {
        printf("%s\n", "Exiting...");
        exit(1);
      };
    }
  }
}


x86 assembly (clang, -O0):
<writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
lea    -0x410(%rbp),%rdi
call   1060 <atoi@plt>
cmp    $0xffffffff,%eax
jne    11ce <writer+0x7e>
lea    0xe48(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    116b <writer+0x1b>

x86 assembly (clang, -O2):
<writer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    (%rdi),%ebp
mov    0x2e84(%rip),%r14
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmp    $0xffffffff,%eax
jne    1170 <writer+0x20>
lea    0xe5d(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [11 x i8] c"Exiting...\00"
define i8* @writer(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %5
br label %9
9: ; preds = %1, %22
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 1024, i32 %11)
%13 = load i32, i32* %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @write(i32 %13, i8* %14, i32 1024)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @atoi(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %9
br label %9
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [11 x i8] c"Exiting...\00"
define noalias i8* @writer(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
br label %6
6: ; preds = %6, %1
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %3, i32 1024, i32 %7)
%9 = call i32 @write(i32 %5, i8* %3, i32 1024)
%10 = call i32 @atoi(i8* %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
}