#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*/ s;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
void *servlet(void *arg) {
  FILE *fp = (FILE *)arg;
  char s[100];
  while (fgets(s, sizeof(s), fp) != 0 && strcmp(s, "bye\n") != 0) {
    printf("msg: %s", s);
    fputs(s, fp);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<servlet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x81(%rbp)
je     11ab <servlet+0x5b>
lea    -0x80(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11be <servlet+0x6e>
jmp    11e0 <servlet+0x90>
lea    -0x80(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1167 <servlet+0x17>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<servlet>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11cb <servlet+0x7b>
lea    0xe86(%rip),%r14
mov    %rsp,%rbx
lea    0xe81(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11cb <servlet+0x7b>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1190 <servlet+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"bye\0A\00"
@.str.1 = [8 x i8] c"msg: %s\00"
define i8* @servlet(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [100 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %3
br label %7
7: ; preds = %18, %1
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i64 @fgets(i8* %8, i32 100, i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = load i32*, i32** %3
%23 = call i32 @fputs(i8* %21, i32* %22)
br label %7
24: ; preds = %16
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
ret i8* null
}

LLVM IR (-O2):
@.str = [5 x i8] c"bye\0A\00"
@.str.1 = [8 x i8] c"msg: %s\00"
define noalias i8* @servlet(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = bitcast i8* %0 to i32*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i64 @fgets(i8* %4, i32 100, i32* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1, %10
%8 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%12 = call i32 @fputs(i8* %4, i32* %3)
%13 = call i64 @fgets(i8* %4, i32 100, i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %10, %1
%16 = call i32 @fclose(i32* %3)
ret i8* null
}