#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 scalar_t__ ssize_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
char *malloc(int);
char *memchr(char *, char, scalar_t__);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
scalar_t__ write(int, char *, int);
int zerossh_askpass(int in_fd, int out_fd) {
  ssize_t ret __attribute__((unused));
  char *buf, *p;
  buf = malloc(4096);
  if (buf == NULL) {
    perror("malloc");
    abort();
  }
  ret = read(in_fd, buf, 4096);
  if (ret < 0) {
    perror("read");
    abort();
  }
  close(in_fd);
  p = memchr(buf, '\n', ret);
  if (p == NULL)
    ret = write(out_fd, buf, ret);
  else
    ret = write(out_fd, buf, p - buf + 1);
  close(out_fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<zerossh_askpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <zerossh_askpass+0x3a>
lea    0xe62(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11dd <zerossh_askpass+0x6d>
lea    0xe36(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   1060 <memchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <zerossh_askpass+0xb1>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1040 <write@plt>
mov    %rax,-0x10(%rbp)
jmp    1242 <zerossh_askpass+0xd2>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1040 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zerossh_askpass>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x1000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f5 <zerossh_askpass+0x85>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %rax,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
js     11fe <zerossh_askpass+0x8e>
mov    %rax,%rbp
mov    %r15d,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rbp,%rdx
call   1060 <memchr@plt>
mov    %eax,%ecx
sub    %ebx,%ecx
add    $0x1,%ecx
test   %rax,%rax
cmovne %ecx,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe04(%rip),%rdi
jmp    1205 <zerossh_askpass+0x95>
lea    0xe02(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @zerossh_askpass(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i8* @malloc(i32 4096)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %2
%15 = load i32, i32* %3
%16 = load i8*, i8** %6
%17 = call i64 @read(i32 %15, i8* %16, i32 4096)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %14
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %6
%27 = load i64, i64* %5
%28 = call i8* @memchr(i8* %26, i8 signext 10, i64 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load i32, i32* %4
%33 = load i8*, i8** %6
%34 = load i64, i64* %5
%35 = trunc i64 %34 to i32
%36 = call i64 @write(i32 %32, i8* %33, i32 %35)
store i64 %36, i64* %5
br label %48
37: ; preds = %23
%38 = load i32, i32* %4
%39 = load i8*, i8** %6
%40 = load i8*, i8** %7
%41 = load i8*, i8** %6
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = add nsw i64 %44, 1
%46 = trunc i64 %45 to i32
%47 = call i64 @write(i32 %38, i8* %39, i32 %46)
store i64 %47, i64* %5
br label %48
48: ; preds = %37, %31
%49 = load i32, i32* %4
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @zerossh_askpass(i32 %0, i32 %1) {
%3 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = tail call i64 @read(i32 %0, i8* %3, i32 4096)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %8
%15 = tail call i32 @close(i32 %0)
%16 = tail call i8* @memchr(i8* %3, i8 signext 10, i64 %9)
%17 = icmp eq i8* %16, null
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %3 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = add i32 %21, 1
%23 = trunc i64 %9 to i32
%24 = select i1 %17, i32 %23, i32 %22
%25 = tail call i64 @write(i32 %1, i8* %3, i32 %24)
%26 = tail call i32 @close(i32 %1)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}