#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getbyte(int, unsigned char *);
int /*<<< orphan*/ printf(char *, unsigned long);
scalar_t__ send_cmd(int, int);
int /*<<< orphan*/ stderr;
int identify(int fd, unsigned long int *ident) {
  unsigned char id[3];
  if (send_cmd(fd, 0x00) && getbyte(fd, &id[0]) && getbyte(fd, &id[1]) &&
      getbyte(fd, &id[2])) {
    *ident = (id[0] << 16) | (id[1] << 8) | id[2];
    printf("ident %06X\n", *ident);
    return 1;
  } else {
    fprintf(stderr, "error identify\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<identify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1060 <send_cmd@plt>
cmp    $0x0,%rax
je     11ec <identify+0xac>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
call   1030 <getbyte@plt>
cmp    $0x0,%rax
je     11ec <identify+0xac>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
add    $0x1,%rsi
call   1030 <getbyte@plt>
cmp    $0x0,%rax
je     11ec <identify+0xac>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
add    $0x2,%rsi
call   1030 <getbyte@plt>
cmp    $0x0,%rax
je     11ec <identify+0xac>
movzbl -0x13(%rbp),%eax
shl    $0x10,%eax
movzbl -0x12(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x11(%rbp),%ecx
or     %ecx,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <identify+0xc8>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<identify>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %esi,%esi
call   1060 <send_cmd@plt>
test   %rax,%rax
je     11c1 <identify+0x81>
lea    0xd(%rsp),%rsi
mov    %ebx,%edi
call   1030 <getbyte@plt>
test   %rax,%rax
je     11c1 <identify+0x81>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
call   1030 <getbyte@plt>
test   %rax,%rax
je     11c1 <identify+0x81>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
call   1030 <getbyte@plt>
test   %rax,%rax
je     11c1 <identify+0x81>
movzbl 0xd(%rsp),%eax
shl    $0x10,%rax
movzbl 0xe(%rsp),%ecx
shl    $0x8,%rcx
or     %rax,%rcx
movzbl 0xf(%rsp),%esi
or     %rcx,%rsi
mov    %rsi,(%r14)
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    11d6 <identify+0x96>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ident %06X\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"error identify\0A\00"
define i32 @identify(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca [3 x i8]
store i32 %0, i32* %4
store i64* %1, i64** %5
%7 = load i32, i32* %4
%8 = call i64 @send_cmd(i32 %7, i32 0)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %44
10: ; preds = %2
%11 = load i32, i32* %4
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%13 = call i64 @getbyte(i32 %11, i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %44
15: ; preds = %10
%16 = load i32, i32* %4
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
%18 = call i64 @getbyte(i32 %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %44
20: ; preds = %15
%21 = load i32, i32* %4
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
%23 = call i64 @getbyte(i32 %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %44
25: ; preds = %20
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = shl i32 %28, 16
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 8
%34 = or i32 %29, %33
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = or i32 %34, %37
%39 = sext i32 %38 to i64
%40 = load i64*, i64** %5
store i64 %39, i64* %40
%41 = load i64*, i64** %5
%42 = load i64, i64* %41
%43 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %42)
store i32 1, i32* %3
br label %47
44: ; preds = %20, %15, %10, %2
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %47
47: ; preds = %44, %25
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [12 x i8] c"ident %06X\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"error identify\0A\00"
define i32 @identify(i32 %0, i64* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @send_cmd(i32 %0, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %30, label %7
7: ; preds = %2
%8 = call i64 @getbyte(i32 %0, i8* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %30, label %10
10: ; preds = %7
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%12 = call i64 @getbyte(i32 %0, i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %10
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%16 = call i64 @getbyte(i32 %0, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %14
%19 = load i8, i8* %4
%20 = zext i8 %19 to i64
%21 = shl nuw nsw i64 %20, 16
%22 = load i8, i8* %11
%23 = zext i8 %22 to i64
%24 = shl nuw nsw i64 %23, 8
%25 = or i64 %24, %21
%26 = load i8, i8* %15
%27 = zext i8 %26 to i64
%28 = or i64 %25, %27
store i64 %28, i64* %1
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %28)
br label %33
30: ; preds = %14, %10, %7, %2
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %18
%34 = phi i32 [ 1, %18 ], [ 0, %30 ]
ret i32 %34
}