#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*/ SHUT_WR;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void write_routine(int sock, char *buf) {
  while (1) {
    fgets(buf, 30, stdin);
    if (!strcmp(buf, "q\n") || !strcmp(buf, "Q\n")) {
      shutdown(sock, SHUT_WR);
      return;
    }
    write(sock, buf, strlen(buf));
  }
}


x86 assembly (clang, -O0):
<write_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     11a8 <write_routine+0x58>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11bf <write_routine+0x6f>
mov    -0x4(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    115f <write_routine+0xf>

x86 assembly (clang, -O2):
<write_routine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e7c(%rip),%r12
mov    (%r12),%edx
mov    %rsi,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11e3 <write_routine+0x93>
lea    0xe74(%rip),%r14
lea    0xe6a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11e3 <write_routine+0x93>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11a0 <write_routine+0x50>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <shutdown@plt>

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

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"q\0A\00"
@.str.1 = [3 x i8] c"Q\0A\00"
@SHUT_WR = global i32 0
define void @write_routine(i32 %0, i8* %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %1, i32 30, i32 %3)
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2, %13
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %13, %7, %2
%11 = load i32, i32* @SHUT_WR
%12 = tail call i32 @shutdown(i32 %0, i32 %11)
ret void
13: ; preds = %7
%14 = tail call i32 @strlen(i8* %1)
%15 = tail call i32 @write(i32 %0, i8* %1, i32 %14)
%16 = load i32, i32* @stdin
%17 = tail call i32 @fgets(i8* %1, i32 30, i32 %16)
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %10, label %7
}