#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 */
scalar_t__ get_tlv_item(int, unsigned char *, unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int get_mfg_state(unsigned char *state) {
  unsigned char buf[128], len;
  memset(buf, 0, 128);
  if (get_tlv_item(0x40, &len, buf) < 0) {
    printf("Get MFG State fail\n");
    return -1;
  }
  if (len != 1) {
    printf("MFG in TLV error\n");
    return -1;
  }
  *state = buf[0];
  printf("%d\n", buf[0]);
  return 0;
}


x86 assembly (clang, -O0):
<get_mfg_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x90(%rbp),%rdx
mov    $0x40,%edi
lea    -0x91(%rbp),%rsi
call   1030 <get_tlv_item@plt>
cmp    $0x0,%rax
jge    118e <get_mfg_state+0x5e>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <get_mfg_state+0xb0>
movzbl -0x91(%rbp),%eax
cmp    $0x1,%eax
je     11b8 <get_mfg_state+0x88>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <get_mfg_state+0xb0>
mov    -0x90(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x90(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mfg_state>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xf(%rsp),%rsi
mov    $0x40,%edi
mov    %rbx,%rdx
call   1040 <get_tlv_item@plt>
test   %rax,%rax
js     1199 <get_mfg_state+0x59>
cmpb   $0x1,0xf(%rsp)
jne    11a2 <get_mfg_state+0x62>
movzbl 0x10(%rsp),%esi
mov    %sil,(%r14)
lea    0xe72(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b3 <get_mfg_state+0x73>
lea    0xe75(%rip),%rdi
jmp    11a9 <get_mfg_state+0x69>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Get MFG State fail\0A\00"
@.str.1 = [18 x i8] c"MFG in TLV error\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @get_mfg_state(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i8
store i8* %0, i8** %3
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 128)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = call i64 @get_tlv_item(i32 64, i8* %5, i8* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %27
13: ; preds = %1
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %27
19: ; preds = %13
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = load i8, i8* %20
%22 = load i8*, i8** %3
store i8 %21, i8* %22
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
store i32 0, i32* %2
br label %27
27: ; preds = %19, %17, %11
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [17 x i8] c"MFG in TLV error\00"
@str.3 = [19 x i8] c"Get MFG State fail\00"
define i32 @get_mfg_state(i8* nocapture writeonly %0) {
%2 = alloca [128 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
%6 = call i64 @get_tlv_item(i32 64, i8* %3, i8* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
br label %19
10: ; preds = %1
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %19
15: ; preds = %10
%16 = load i8, i8* %4
store i8 %16, i8* %0
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %13, %8
%20 = phi i32 [ -1, %8 ], [ -1, %13 ], [ 0, %15 ]
ret i32 %20
}