#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*/ dump_hex(char *, int);
int /*<<< orphan*/ package_get_device_description(char *);
int /*<<< orphan*/ printf(char *);
int write_buffer(int, char *, char *);
int get_device_info(int tty) {
  char buffer[17];
  int res;
  printf("++ tracker id:\n");
  package_get_device_description(buffer);
  res = write_buffer(tty, buffer, buffer);
  if (res < 17) {
    printf("?? Can't get device info, package is too short\n");
    return res;
  }
  printf("-- id will be:");
  dump_hex(buffer + 0x07, 0x06);
  printf("\n-- Other values unknown for now.\n");
  return 0;
}


x86 assembly (clang, -O0):
<get_device_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <package_get_device_description@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <write_buffer@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x11,-0x24(%rbp)
jge    1194 <get_device_info+0x54>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <get_device_info+0x85>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
add    $0x7,%rdi
mov    $0x6,%esi
call   1060 <dump_hex@plt>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_device_info>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <package_get_device_description@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1040 <write_buffer@plt>
cmp    $0x11,%eax
jge    118c <get_device_info+0x3c>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
jmp    11b0 <get_device_info+0x60>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
lea    0x7(%rsp),%rdi
mov    $0x6,%esi
call   1070 <dump_hex@plt>
xor    %ebx,%ebx
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"++ tracker id:\0A\00"
@.str.1 = [48 x i8] c"?? Can't get device info, package is too short\0A\00"
@.str.2 = [15 x i8] c"-- id will be:\00"
@.str.3 = [35 x i8] c"\0A-- Other values unknown for now.\0A\00"
define i32 @get_device_info(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [17 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%8 = call i32 @package_get_device_description(i8* %7)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%12 = call i32 @write_buffer(i32 %9, i8* %10, i8* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 17
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %24
18: ; preds = %1
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 7
%22 = call i32 @dump_hex(i8* %21, i32 6)
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %24
24: ; preds = %18, %15
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str.2 = [15 x i8] c"-- id will be:\00"
@str = [15 x i8] c"++ tracker id:\00"
@str.4 = [34 x i8] c"\0A-- Other values unknown for now.\00"
@str.5 = [47 x i8] c"?? Can't get device info, package is too short\00"
define i32 @get_device_info(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%5 = call i32 @package_get_device_description(i8* %3)
%6 = call i32 @write_buffer(i32 %0, i8* %3, i8* %3)
%7 = icmp slt i32 %6, 17
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 7
%11 = call i32 @dump_hex(i8* %10, i32 6)
br label %12
12: ; preds = %1, %8
%13 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0), %1 ]
%14 = phi i32 [ 0, %8 ], [ %6, %1 ]
%15 = call i32 @puts(i8* dereferenceable(1) %13)
ret i32 %14
}