#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 */
scalar_t__ readchar(int, unsigned char *, int);
int newton_init(int fd, long *id, long *extra) {
  int i;
  unsigned char c;
  unsigned char response[35] = {
      0x16, 0x10, 0x02, 0x64, 0x5f, 0x69, 0x64, 0x00, 0x00, 0x00, 0x0c, 0x6b,
      0x79, 0x62, 0x64, 0x61, 0x70, 0x70, 0x6c, 0x00, 0x00, 0x00, 0x01, 0x6e,
      0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10, 0x03, 0xdd, 0xe7};
  for (i = 0; i < 35; i++)
    if (readchar(fd, &c, 400) || (c != response[i]))
      return -1;
  return 0;
}


x86 assembly (clang, -O0):
<newton_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec2(%rip),%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x23,-0x1c(%rbp)
jge    11a8 <newton_init+0x88>
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x190,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    1189 <newton_init+0x69>
movzbl -0x1d(%rbp),%eax
movslq -0x1c(%rbp),%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     1195 <newton_init+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <newton_init+0x8f>
jmp    119a <newton_init+0x7a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <newton_init+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0x7(%rsp),%r14
lea    0xed9(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x190,%edx
call   1030 <readchar@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1163 <newton_init+0x53>
movzbl 0x7(%rsp),%ecx
cmp    (%rbx,%r15,1),%cl
jne    1163 <newton_init+0x53>
add    $0x1,%rbx
cmp    $0x23,%rbx
jne    1130 <newton_init+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.newton_init.response = [35 x i8] c"\16\10\02d_id\00\00\00\0Ckybdappl\00\00\00\01nofm\00\00\00\00\10\03\DD\E7"
define i32 @newton_init(i32 %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i8
%10 = alloca [35 x i8]
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%11 = bitcast [35 x i8]* %10 to i8*
store i32 0, i32* %8
br label %12
12: ; preds = %30, %3
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 35
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load i32, i32* %5
%17 = call i64 @readchar(i32 %16, i8* %9, i32 400)
%18 = icmp ne i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %15
%20 = load i8, i8* %9
%21 = zext i8 %20 to i32
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [35 x i8], [35 x i8]* %10, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %21, %26
br i1 %27, label %28, label %29
28: ; preds = %19, %15
store i32 -1, i32* %4
br label %34
29: ; preds = %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %12
33: ; preds = %12
store i32 0, i32* %4
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@__const.newton_init.response = [35 x i8] c"\16\10\02d_id\00\00\00\0Ckybdappl\00\00\00\01nofm\00\00\00\00\10\03\DD\E7"
define i32 @newton_init(i32 %0, i64* nocapture readnone %1, i64* nocapture readnone %2) {
%4 = alloca i8
br label %8
5: ; preds = %12
%6 = add nuw nsw i64 %9, 1
%7 = icmp eq i64 %6, 35
br i1 %7, label %17, label %8
8: ; preds = %3, %5
%9 = phi i64 [ 0, %3 ], [ %6, %5 ]
%10 = call i64 @readchar(i32 %0, i8* %4, i32 400)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8, i8* %4
%14 = getelementptr inbounds [35 x i8], [35 x i8]* @__const.newton_init.response, i64 0, i64 %9
%15 = load i8, i8* %14
%16 = icmp eq i8 %13, %15
br i1 %16, label %5, label %17
17: ; preds = %5, %8, %12
%18 = phi i32 [ -1, %12 ], [ -1, %8 ], [ 0, %5 ]
ret i32 %18
}