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

/* Variables and functions */
int EOF;
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int getbyte(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int ihx2bin(FILE *ihx, FILE *bin) {
  int byte;
  while ((byte = getbyte(ihx)) != EOF && byte != -999) {
    char ch[1] = {byte};
    if (fwrite(ch, 1, 1, bin) != 1) {
      perror("cannot write to bin file");
      return 1;
    }
  }
  return byte == -999;
}


x86 assembly (clang, -O0):
<ihx2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getbyte@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e91(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
je     116f <ihx2bin+0x3f>
cmpl   $0xfffffc19,-0x1c(%rbp)
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    117f <ihx2bin+0x4f>
jmp    11bf <ihx2bin+0x8f>
mov    -0x1c(%rbp),%eax
mov    %al,-0x1d(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
cmp    $0x1,%eax
je     11ba <ihx2bin+0x8a>
lea    0xe57(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <ihx2bin+0xa1>
jmp    1140 <ihx2bin+0x10>
cmpl   $0xfffffc19,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihx2bin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <getbyte@plt>
cmp    $0xfffffc19,%eax
je     1193 <ihx2bin+0x63>
mov    0x2e97(%rip),%r12
cmp    (%r12),%eax
je     1193 <ihx2bin+0x63>
lea    0x7(%rsp),%r15
nopl   0x0(%rax)
mov    %al,0x7(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
cmp    $0x1,%eax
jne    11ab <ihx2bin+0x7b>
mov    %rbx,%rdi
call   1030 <getbyte@plt>
cmp    $0xfffffc19,%eax
je     1193 <ihx2bin+0x63>
cmp    (%r12),%eax
jne    1160 <ihx2bin+0x30>
xor    %ecx,%ecx
cmp    $0xfffffc19,%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe4e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%ecx
jmp    119d <ihx2bin+0x6d>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [25 x i8] c"cannot write to bin file\00"
define i32 @ihx2bin(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [1 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %8
8: ; preds = %28, %2
%9 = load i32*, i32** %4
%10 = call i32 @getbyte(i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, -999
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %29
18: ; preds = %16
%19 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %6
%21 = trunc i32 %20 to i8
store i8 %21, i8* %19
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%23 = load i32*, i32** %5
%24 = call i32 @fwrite(i8* %22, i32 1, i32 1, i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
28: ; preds = %18
br label %8
29: ; preds = %16
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -999
%32 = zext i1 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %29, %26
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [25 x i8] c"cannot write to bin file\00"
define i32 @ihx2bin(i32* %0, i32* nocapture %1) {
%3 = alloca [1 x i8]
%4 = tail call i32 @getbyte(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
%7 = icmp ne i32 %4, -999
%8 = and i1 %7, %6
br i1 %8, label %9, label %24
9: ; preds = %2
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
br label %17
11: ; preds = %17
%12 = tail call i32 @getbyte(i32* %0)
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
%15 = icmp ne i32 %12, -999
%16 = and i1 %15, %14
br i1 %16, label %17, label %24
17: ; preds = %9, %11
%18 = phi i32 [ %4, %9 ], [ %12, %11 ]
%19 = trunc i32 %18 to i8
store i8 %19, i8* %10
%20 = call i32 @fwrite(i8* %10, i32 1, i32 1, i32* %1)
%21 = icmp eq i32 %20, 1
br i1 %21, label %11, label %22
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %28
24: ; preds = %11, %2
%25 = phi i32 [ %4, %2 ], [ %12, %11 ]
%26 = icmp eq i32 %25, -999
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %22, %24
%29 = phi i32 [ 1, %22 ], [ %27, %24 ]
ret i32 %29
}