#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 */
int ir_read_char(int);
unsigned char *ir_read_code(unsigned long timeout) {
  static unsigned char codebuf[6];
  int i, datum;
  datum = ir_read_char(timeout);
  if (datum < 0)
    return NULL;
  codebuf[0] = (unsigned char)datum;
  for (i = 1; i < 6; i++) {
    datum = ir_read_char((1 * 1000));
    if (datum < 0) {
      return NULL;
    } else {
      codebuf[i] = (unsigned char)datum;
    }
  }
  return codebuf;
}


x86 assembly (clang, -O0):
<ir_read_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1030 <ir_read_char@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1141 <ir_read_code+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <ir_read_code+0xa0>
mov    -0x18(%rbp),%eax
mov    %al,0x2edf(%rip)
movl   $0x1,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    11a5 <ir_read_code+0x95>
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117f <ir_read_code+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <ir_read_code+0xa0>
mov    -0x18(%rbp),%eax
mov    %al,%dl
movslq -0x14(%rbp),%rcx
lea    0x2e9a(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1197 <ir_read_code+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <ir_read_code+0x41>
lea    0x2e7d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ir_read_code>:
push   %rax
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2f09(%rip)
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2ef6(%rip)
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2ee3(%rip)
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2ed0(%rip)
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2ebd(%rip)
mov    $0x3e8,%edi
call   1030 <ir_read_char@plt>
test   %eax,%eax
js     118d <ir_read_code+0x7d>
mov    %al,0x2eaa(%rip)
lea    0x2e9e(%rip),%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@ir_read_code.codebuf = internal global [6 x i8] zeroinitializer
define i8* @ir_read_code(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = trunc i64 %6 to i32
%8 = call i32 @ir_read_char(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %34
12: ; preds = %1
%13 = load i32, i32* %5
%14 = trunc i32 %13 to i8
store i8 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 0)
store i32 1, i32* %4
br label %15
15: ; preds = %30, %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 6
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = call i32 @ir_read_char(i32 1000)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* null, i8** %2
br label %34
23: ; preds = %18
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %23
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %15
33: ; preds = %15
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 0), i8** %2
br label %34
34: ; preds = %33, %22, %11
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@ir_read_code.codebuf = internal global [6 x i8] zeroinitializer
define i8* @ir_read_code(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = tail call i32 @ir_read_char(i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = trunc i32 %3 to i8
store i8 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 0)
%7 = tail call i32 @ir_read_char(i32 1000)
%8 = icmp slt i32 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %5
%10 = trunc i32 %7 to i8
store i8 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 1)
%11 = tail call i32 @ir_read_char(i32 1000)
%12 = icmp slt i32 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %9
%14 = trunc i32 %11 to i8
store i8 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 2)
%15 = tail call i32 @ir_read_char(i32 1000)
%16 = icmp slt i32 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = trunc i32 %15 to i8
store i8 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 3)
%19 = tail call i32 @ir_read_char(i32 1000)
%20 = icmp slt i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = trunc i32 %19 to i8
store i8 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 4)
%23 = tail call i32 @ir_read_char(i32 1000)
%24 = icmp slt i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = trunc i32 %23 to i8
store i8 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 5)
br label %27
27: ; preds = %5, %9, %13, %17, %21, %25, %1
%28 = phi i8* [ null, %1 ], [ null, %5 ], [ null, %9 ], [ null, %13 ], [ null, %17 ], [ null, %21 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @ir_read_code.codebuf, i64 0, i64 0), %25 ]
ret i8* %28
}