#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) {
  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    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeca(%rip),%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x23,-0xc(%rbp)
jge    11a0 <newton_init+0x80>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x190,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    1181 <newton_init+0x61>
movzbl -0xd(%rbp),%eax
movslq -0xc(%rbp),%rcx
movzbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     118d <newton_init+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <newton_init+0x87>
jmp    1192 <newton_init+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <newton_init+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [35 x i8]
store i32 %0, i32* %3
%7 = bitcast [35 x i8]* %6 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %26, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 35
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i64 @readchar(i32 %12, i8* %5, i32 400)
%14 = icmp ne i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [35 x i8], [35 x i8]* %6, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %17, %22
br i1 %23, label %24, label %25
24: ; preds = %15, %11
store i32 -1, i32* %2
br label %30
25: ; preds = %15
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %8
29: ; preds = %8
store i32 0, i32* %2
br label %30
30: ; preds = %29, %24
%31 = load i32, i32* %2
ret i32 %31
}

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