#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*/ enough_mem(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ isdigit(int);
scalar_t__ malloc(size_t);
char *readline(int);
int /*<<< orphan*/ say(int, char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *);
int strlen(char *);
char *passall(int sourcefd, int targetfd) {
  char *line = 0, *sendbuf = 0;
  size_t sendbufsize;
  while ((line = readline(sourcefd))) {
    sendbufsize = strlen(line) + 3;
    sendbuf = (char *)malloc(sendbufsize);
    enough_mem(sendbuf);
    snprintf(sendbuf, sendbufsize, "%s\r\n", line);
    free(line);
    say(targetfd, sendbuf);
    if (strlen(sendbuf) > 4 && isdigit((int)sendbuf[0]) &&
        isdigit((int)sendbuf[1]) && isdigit((int)sendbuf[2]) &&
        sendbuf[3] == ' ') {
      break;
    } else {
      free(sendbuf);
      sendbuf = 0;
    }
  }
  return sendbuf;
}


x86 assembly (clang, -O0):
<passall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <readline@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     128b <passall+0x10b>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x3,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <enough_mem@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe11(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <say@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x4,%eax
jle    1275 <passall+0xf5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1275 <passall+0xf5>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1275 <passall+0xf5>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1275 <passall+0xf5>
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x20,%eax
jne    1275 <passall+0xf5>
jmp    128b <passall+0x10b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    119e <passall+0x1e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passall>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %edi,%r13d
call   1080 <readline@plt>
test   %rax,%rax
je     125e <passall+0xde>
mov    %rax,%rbp
lea    0xe57(%rip),%r15
jmp    11cc <passall+0x4c>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%edi
call   1080 <readline@plt>
mov    %rax,%rbp
test   %rax,%rax
je     125e <passall+0xde>
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    $0x3,%eax
movslq %eax,%r14
mov    %r14,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <enough_mem@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   10a0 <say@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jl     11b0 <passall+0x30>
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     11b0 <passall+0x30>
movsbl 0x1(%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     11b0 <passall+0x30>
movsbl 0x2(%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     11b0 <passall+0x30>
cmpb   $0x20,0x3(%rbx)
jne    11b0 <passall+0x30>
mov    %rbx,%rax
jmp    1260 <passall+0xe0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0D\0A\00"
define i8* @passall(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* null, i8** %5
store i8* null, i8** %6
br label %8
8: ; preds = %65, %2
%9 = load i32, i32* %3
%10 = call i8* @readline(i32 %9)
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %66
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 3
%16 = sext i32 %15 to i64
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @enough_mem(i8* %20)
%22 = load i8*, i8** %6
%23 = load i64, i64* %7
%24 = load i8*, i8** %5
%25 = call i32 @snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %4
%29 = load i8*, i8** %6
%30 = call i32 @say(i32 %28, i8* %29)
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = icmp sgt i32 %32, 4
br i1 %33, label %34, label %62
34: ; preds = %12
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i64 @isdigit(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %62
41: ; preds = %34
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i64 @isdigit(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %41
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i64 @isdigit(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %48
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 3
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 32
br i1 %60, label %61, label %62
61: ; preds = %55
br label %66
62: ; preds = %55, %48, %41, %34, %12
%63 = load i8*, i8** %6
%64 = call i32 @free(i8* %63)
store i8* null, i8** %6
br label %65
65: ; preds = %62
br label %8
66: ; preds = %61, %8
%67 = load i8*, i8** %6
ret i8* %67
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0D\0A\00"
define i8* @passall(i32 %0, i32 %1) {
%3 = tail call i8* @readline(i32 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %45, label %5
5: ; preds = %2, %39
%6 = phi i8* [ %41, %39 ], [ %3, %2 ]
%7 = tail call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 3
%9 = sext i32 %8 to i64
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @enough_mem(i8* %11)
%13 = tail call i32 @snprintf(i8* %11, i64 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6)
%14 = tail call i32 @free(i8* %6)
%15 = tail call i32 @say(i32 %1, i8* %11)
%16 = tail call i32 @strlen(i8* %11)
%17 = icmp sgt i32 %16, 4
br i1 %17, label %18, label %39
18: ; preds = %5
%19 = load i8, i8* %11
%20 = sext i8 %19 to i32
%21 = tail call i64 @isdigit(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %39, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %11, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = tail call i64 @isdigit(i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %39, label %29
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %11, i64 2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = tail call i64 @isdigit(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %11, i64 3
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 32
br i1 %38, label %43, label %39
39: ; preds = %35, %29, %23, %18, %5
%40 = tail call i32 @free(i8* %11)
%41 = tail call i8* @readline(i32 %0)
%42 = icmp eq i8* %41, null
br i1 %42, label %45, label %5
43: ; preds = %35
%44 = inttoptr i64 %10 to i8*
br label %45
45: ; preds = %39, %43, %2
%46 = phi i8* [ null, %2 ], [ %44, %43 ], [ null, %39 ]
ret i8* %46
}