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

/* Variables and functions */
scalar_t__ readchar(int, unsigned char *, int);
int newton_init(int fd, unsigned long *id, unsigned 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 < sizeof(response); 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)
movslq -0x1c(%rbp),%rax
cmp    $0x23,%rax
jae    11ac <newton_init+0x8c>
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x190,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    118d <newton_init+0x6d>
movzbl -0x1d(%rbp),%eax
movslq -0x1c(%rbp),%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     1199 <newton_init+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <newton_init+0x93>
jmp    119e <newton_init+0x7e>
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 = %31, %3
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %14, 35
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32, i32* %5
%18 = call i64 @readchar(i32 %17, i8* %9, i32 400)
%19 = icmp ne i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = load i8, i8* %9
%22 = zext i8 %21 to i32
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [35 x i8], [35 x i8]* %10, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp ne i32 %22, %27
br i1 %28, label %29, label %30
29: ; preds = %20, %16
store i32 -1, i32* %4
br label %35
30: ; preds = %20
br label %31
31: ; preds = %30
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %12
34: ; preds = %12
store i32 0, i32* %4
br label %35
35: ; preds = %34, %29
%36 = load i32, i32* %4
ret i32 %36
}

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 %7
5: ; preds = %11
%6 = icmp eq i64 %16, 35
br i1 %6, label %17, label %7
7: ; preds = %3, %5
%8 = phi i64 [ 0, %3 ], [ %16, %5 ]
%9 = call i64 @readchar(i32 %0, i8* %4, i32 400)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i8, i8* %4
%13 = getelementptr inbounds [35 x i8], [35 x i8]* @__const.newton_init.response, i64 0, i64 %8
%14 = load i8, i8* %13
%15 = icmp eq i8 %12, %14
%16 = add nuw nsw i64 %8, 1
br i1 %15, label %5, label %17
17: ; preds = %5, %7, %11
%18 = phi i32 [ -1, %11 ], [ -1, %7 ], [ 0, %5 ]
ret i32 %18
}