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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int read(int, unsigned char *, int);
get_incoming(int fd) {
  FILE *out;
  int len, i, offs = 0;
  unsigned char buf[BUFSIZ];
  out = fopen("client.out", "w");
  while ((len = read(fd, buf, BUFSIZ)) > 0) {
    fprintf(out, "len is %d\n", len);
    for (i = 0; i < len; i++) {
      fprintf(out, "%d:%d", i, buf[i]);
      if (buf[i] >= ' ' && buf[i] < 'z')
        fprintf(out, " %c", buf[i]);
      fprintf(out, "\n");
    }
    fflush(out);
  }
  close(fd);
  fclose(out);
}


x86 assembly (clang, -O0):
<get_incoming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe5b(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1295 <get_incoming+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1287 <get_incoming+0x127>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1267 <get_incoming+0x107>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jge    1267 <get_incoming+0x107>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f2 <get_incoming+0x92>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
jmp    11b5 <get_incoming+0x55>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_incoming>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2e58(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe5c(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    (%r12),%edx
mov    %r14d,-0x2c(%rbp)
mov    %r14d,%edi
mov    %r15,%rsi
call   1060 <read@plt>
test   %eax,%eax
jle    1271 <get_incoming+0x101>
mov    %eax,%r14d
jmp    1203 <get_incoming+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    -0x2c(%rbp),%edi
mov    %r15,%rsi
call   1060 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1271 <get_incoming+0x101>
mov    %rbx,%rdi
lea    0xe00(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14d,%r13d
xor    %r14d,%r14d
jmp    1236 <get_incoming+0xc6>
nop
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     11e0 <get_incoming+0x70>
movzbl (%r15,%r14,1),%r12d
mov    %rbx,%rdi
lea    0xdd3(%rip),%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    -0x20(%r12),%eax
cmp    $0x59,%al
ja     1220 <get_incoming+0xb0>
mov    %rbx,%rdi
lea    0xdb9(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1220 <get_incoming+0xb0>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    %rbx,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [11 x i8] c"client.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [11 x i8] c"len is %d\0A\00"
@.str.3 = [6 x i8] c"%d:%d\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @get_incoming(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %3
store i32 0, i32* %7
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
br label %15
15: ; preds = %64, %1
%16 = load i32, i32* %3
%17 = load i32, i32* @BUFSIZ
%18 = call i32 @read(i32 %16, i8* %13, i32 %17)
store i32 %18, i32* %5
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %67
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %22)
store i32 0, i32* %6
br label %24
24: ; preds = %61, %20
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %64
28: ; preds = %24
%29 = load i32*, i32** %4
%30 = load i32, i32* %6
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %13, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %35)
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %13, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = icmp sge i32 %41, 32
br i1 %42, label %43, label %58
43: ; preds = %28
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %13, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp slt i32 %48, 122
br i1 %49, label %50, label %58
50: ; preds = %43
%51 = load i32*, i32** %4
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %13, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %50, %43, %28
%59 = load i32*, i32** %4
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %58
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %24
64: ; preds = %24
%65 = load i32*, i32** %4
%66 = call i32 @fflush(i32* %65)
br label %15
67: ; preds = %15
%68 = load i32, i32* %3
%69 = call i32 @close(i32 %68)
%70 = load i32*, i32** %4
%71 = call i32 @fclose(i32* %70)
%72 = load i8*, i8** %8
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [11 x i8] c"client.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [11 x i8] c"len is %d\0A\00"
@.str.3 = [6 x i8] c"%d:%d\00"
@.str.4 = [4 x i8] c" %c\00"
define i32 @get_incoming(i32 %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @BUFSIZ
%7 = call i32 @read(i32 %0, i8* %4, i32 %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %1, %28
%10 = phi i32 [ %31, %28 ], [ %7, %1 ]
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = zext i32 %10 to i64
br label %13
13: ; preds = %9, %24
%14 = phi i64 [ 0, %9 ], [ %26, %24 ]
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = trunc i64 %14 to i32
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %17)
%20 = add i8 %16, -32
%21 = icmp ult i8 %20, 90
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %24
24: ; preds = %22, %13
%25 = tail call i32 @fputc(i32 10, i32* %5)
%26 = add nuw nsw i64 %14, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %13
28: ; preds = %24
%29 = tail call i32 @fflush(i32* %5)
%30 = load i32, i32* @BUFSIZ
%31 = call i32 @read(i32 %0, i8* %4, i32 %30)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %9, label %33
33: ; preds = %28, %1
%34 = tail call i32 @close(i32 %0)
%35 = tail call i32 @fclose(i32* %5)
ret i32 undef
}