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

/* Variables and functions */
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void write_routine(int fd) {
  char buf[1024];
  while (1) {
    fputs(">>> ", stdout);
    fgets(buf, sizeof(buf), stdin);
    if (!strcmp(buf, "q\n") || !strcmp(buf, "Q\n")) {
      shutdown(fd, SHUT_WR);
      return;
    }
    write(fd, buf, strlen(buf));
  }
}


x86 assembly (clang, -O0):
<write_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1060 <fputs@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1070 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
je     11d5 <write_routine+0x75>
lea    -0x410(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    11ef <write_routine+0x8f>
mov    -0x4(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
add    $0x420,%rsp
pop    %rbp
ret
mov    -0x4(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    116e <write_routine+0xe>

x86 assembly (clang, -O2):
<write_routine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2e61(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    $0xa71,%r13d
mov    (%rsp),%eax
xor    %r13d,%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
je     1216 <write_routine+0xc6>
mov    $0xa51,%r15d
mov    %rsp,%rbx
lea    0xe4a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%eax
xor    %r15d,%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
je     1216 <write_routine+0xc6>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <fputs@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    (%rsp),%eax
xor    %r13d,%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
jne    11c0 <write_routine+0x70>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c">>> \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [3 x i8] c"q\0A\00"
@.str.2 = [3 x i8] c"Q\0A\00"
@SHUT_WR = global i32 0
define void @write_routine(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 %0, i32* %2
br label %4
4: ; preds = %1, %21
%5 = load i32, i32* @stdout
%6 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 1024, i32 %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13, %4
%18 = load i32, i32* %2
%19 = load i32, i32* @SHUT_WR
%20 = call i32 @shutdown(i32 %18, i32 %19)
ret void
21: ; preds = %13
%22 = load i32, i32* %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
br label %4
}

LLVM IR (-O2):
@.str = [5 x i8] c">>> \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [3 x i8] c"q\0A\00"
@.str.2 = [3 x i8] c"Q\0A\00"
@SHUT_WR = global i32 0
define void @write_routine(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* @stdout
%5 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 1024, i32 %6)
%8 = call i32 @bcmp(i8* dereferenceable(3) %3, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1, %16
%11 = call i32 @bcmp(i8* dereferenceable(3) %3, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %16, %10, %1
%14 = load i32, i32* @SHUT_WR
%15 = call i32 @shutdown(i32 %0, i32 %14)
ret void
16: ; preds = %10
%17 = call i32 @strlen(i8* %3)
%18 = call i32 @write(i32 %0, i8* %3, i32 %17)
%19 = load i32, i32* @stdout
%20 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %3, i32 1024, i32 %21)
%23 = call i32 @bcmp(i8* dereferenceable(3) %3, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %13, label %10
}