#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*/ PR_GET_DUMPABLE;
int prctl(int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int dumpable_server() {
  char buf[256];
  int ret;
  for (;;) {
    ret = read(0, buf, sizeof(buf));
    if (ret == 0)
      break;
    ret = snprintf(buf, sizeof(buf), "DUMPABLE:%d\n", prctl(PR_GET_DUMPABLE));
    write(1, buf, ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<dumpable_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jne    1176 <dumpable_server+0x36>
jmp    11ce <dumpable_server+0x8e>
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <prctl@plt>
mov    -0x110(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe59(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x104(%rbp)
lea    -0x100(%rbp),%rsi
mov    -0x104(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    114b <dumpable_server+0xb>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpable_server>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11ac <dumpable_server+0x6c>
mov    0x2e82(%rip),%r15
lea    0xe93(%rip),%r14
mov    %rsp,%rbx
mov    (%r15),%edi
call   1060 <prctl@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1170 <dumpable_server+0x30>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"DUMPABLE:%d\0A\00"
@PR_GET_DUMPABLE = global i32 0
define i32 @dumpable_server() {
%1 = alloca [256 x i8]
%2 = alloca i32
br label %3
3: ; preds = %9, %0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 256)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
br label %17
9: ; preds = %3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = load i32, i32* @PR_GET_DUMPABLE
%12 = call i32 @prctl(i32 %11)
%13 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @write(i32 1, i8* %14, i32 %15)
br label %3
17: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"DUMPABLE:%d\0A\00"
@PR_GET_DUMPABLE = global i32 0
define i32 @dumpable_server() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 256)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0, %5
%6 = load i32, i32* @PR_GET_DUMPABLE
%7 = call i32 @prctl(i32 %6)
%8 = call i32 @snprintf(i8* %2, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @write(i32 1, i8* %2, i32 %8)
%10 = call i32 @read(i32 0, i8* %2, i32 256)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %5, %0
ret i32 0
}