#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ do_instruction(int, int *, int *);
int read_signature(int fd, uint8_t sig[4]) {
  uint8_t tx[4], rx[4];
  uint8_t i;
  tx[0] = 0x30;
  tx[1] = tx[2] = tx[3] = 0;
  for (i = 0; i < 4; i++) {
    tx[2] = i;
    if (!do_instruction(fd, tx, rx))
      return 0;
    sig[i] = rx[3];
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x30,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    1193 <read_signature+0x83>
mov    -0x34(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <do_instruction@plt>
cmp    $0x0,%eax
jne    1177 <read_signature+0x67>
movl   $0x0,-0x4(%rbp)
jmp    119a <read_signature+0x8a>
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1142 <read_signature+0x32>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_signature>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x30,(%rsp)
movq   $0x0,0x4(%rsp)
movl   $0x0,0xc(%rsp)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
call   1030 <do_instruction@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11bb <read_signature+0xab>
mov    0x1c(%rsp),%eax
mov    %eax,(%rbx)
movl   $0x1,0x8(%rsp)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1030 <do_instruction@plt>
test   %eax,%eax
je     11bb <read_signature+0xab>
mov    0x1c(%rsp),%eax
mov    %eax,0x4(%rbx)
movl   $0x2,0x8(%rsp)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1030 <do_instruction@plt>
test   %eax,%eax
je     11bb <read_signature+0xab>
mov    0x1c(%rsp),%eax
mov    %eax,0x8(%rbx)
movl   $0x3,0x8(%rsp)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1030 <do_instruction@plt>
test   %eax,%eax
je     11bb <read_signature+0xab>
mov    0x1c(%rsp),%eax
mov    %eax,0xc(%rbx)
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @read_signature(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [4 x i32]
%4 = alloca [4 x i32]
%5 = bitcast [4 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %4 to i8*
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32 48, i32* %7
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%12 = bitcast i32* %9 to i8*
%13 = call i32 @do_instruction(i32 %0, i32* %7, i32* %10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %2
%16 = load i32, i32* %11
store i32 %16, i32* %1
store i32 1, i32* %8
%17 = call i32 @do_instruction(i32 %0, i32* %7, i32* %10)
%18 = icmp eq i32 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %15
%20 = load i32, i32* %11
%21 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %20, i32* %21
store i32 2, i32* %8
%22 = call i32 @do_instruction(i32 %0, i32* %7, i32* %10)
%23 = icmp eq i32 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %19
%25 = load i32, i32* %11
%26 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %25, i32* %26
store i32 3, i32* %8
%27 = call i32 @do_instruction(i32 %0, i32* %7, i32* %10)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = load i32, i32* %11
%31 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %30, i32* %31
br label %32
32: ; preds = %29, %24, %19, %15, %2
%33 = phi i32 [ 0, %2 ], [ 0, %15 ], [ 0, %19 ], [ 0, %24 ], [ 1, %29 ]
ret i32 %33
}