#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 /*<<< orphan*/ enable_programming(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int write_config_byte(int spidev, const char *name, uint8_t wr0, uint8_t wr1,
                      uint8_t rd0, uint8_t rd1, uint8_t val) {
  uint8_t tx[4], rx[4];
  tx[0] = rd0;
  tx[1] = rd1;
  tx[2] = tx[3] = 0;
  if (!do_instruction(spidev, tx, rx))
    return 0;
  if (rx[3] == val) {
    fprintf(stderr, "Not writing %s; already set to 0x%x\n", name, val);
    return 1;
  }
  tx[0] = wr0;
  tx[1] = wr1;
  tx[2] = 0;
  tx[3] = val;
  if (!do_instruction(spidev, tx, rx))
    return 0;
  fprintf(stderr, "Set %s to 0x%x; verifying... ", name, val);
  if (!enable_programming(spidev))
    return 0;
  tx[0] = rd0;
  tx[1] = rd1;
  tx[2] = tx[3] = 0;
  if (!do_instruction(spidev, tx, rx))
    return 0;
  if (rx[3] == val) {
    fprintf(stderr, "ok\n");
    return 1;
  } else {
    fprintf(stderr, "mismatch (got 0x%x)\n", rx[3]);
    return 0;
  }
}


x86 assembly (clang, -O0):
<write_config_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <do_instruction@plt>
cmp    $0x0,%eax
jne    118f <write_config_byte+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jne    11c5 <write_config_byte+0x95>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    0x10(%rbp),%ecx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <do_instruction@plt>
cmp    $0x0,%eax
jne    1203 <write_config_byte+0xd3>
movl   $0x0,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    0x10(%rbp),%ecx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1030 <enable_programming@plt>
cmp    $0x0,%eax
jne    123e <write_config_byte+0x10e>
movl   $0x0,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <do_instruction@plt>
cmp    $0x0,%eax
jne    127d <write_config_byte+0x14d>
movl   $0x0,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jne    12ac <write_config_byte+0x17c>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cd <write_config_byte+0x19d>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_config_byte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %rsi,0x18(%rsp)
mov    %edi,%ebp
mov    %r8d,(%rsp)
mov    %r9d,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
lea    0x20(%rsp),%rdx
call   1050 <do_instruction@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     125f <write_config_byte+0x12f>
mov    0x70(%rsp),%ecx
cmp    %ecx,0x2c(%rsp)
jne    11aa <write_config_byte+0x7a>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
jmp    125f <write_config_byte+0x12f>
mov    %r13d,(%rsp)
mov    %r14d,0x4(%rsp)
movl   $0x0,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rsp,%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
mov    %ecx,%r13d
call   1050 <do_instruction@plt>
test   %eax,%eax
je     125f <write_config_byte+0x12f>
mov    0x2e00(%rip),%r14
mov    (%r14),%edi
lea    0xe3b(%rip),%rsi
xor    %ebx,%ebx
mov    0x18(%rsp),%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%edi
call   1030 <enable_programming@plt>
test   %eax,%eax
je     125f <write_config_byte+0x12f>
mov    %r12d,(%rsp)
mov    %r15d,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   1050 <do_instruction@plt>
test   %eax,%eax
mov    0x70(%rsp),%eax
je     125f <write_config_byte+0x12f>
mov    0x2c(%rsp),%edx
mov    (%r14),%edi
cmp    %eax,%edx
jne    124f <write_config_byte+0x11f>
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
jmp    125f <write_config_byte+0x12f>
lea    0xdf1(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Not writing %s; already set to 0x%x\0A\00"
@.str.1 = [30 x i8] c"Set %s to 0x%x; verifying... \00"
@.str.2 = [4 x i8] c"ok\0A\00"
@.str.3 = [21 x i8] c"mismatch (got 0x%x)\0A\00"
define i32 @write_config_byte(i32 %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [4 x i32]
%17 = alloca [4 x i32]
store i32 %0, i32* %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%18 = load i32, i32* %13
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
store i32 %18, i32* %19
%20 = load i32, i32* %14
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 1
store i32 %20, i32* %21
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 3
store i32 0, i32* %22
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 2
store i32 0, i32* %23
%24 = load i32, i32* %9
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%27 = call i32 @do_instruction(i32 %24, i32* %25, i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %7
store i32 0, i32* %8
br label %89
30: ; preds = %7
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 3
%32 = load i32, i32* %31
%33 = load i32, i32* %15
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = load i32, i32* %15
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %37, i32 %38)
store i32 1, i32* %8
br label %89
40: ; preds = %30
%41 = load i32, i32* %11
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
store i32 %41, i32* %42
%43 = load i32, i32* %12
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 1
store i32 %43, i32* %44
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 2
store i32 0, i32* %45
%46 = load i32, i32* %15
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 3
store i32 %46, i32* %47
%48 = load i32, i32* %9
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%51 = call i32 @do_instruction(i32 %48, i32* %49, i32* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %40
store i32 0, i32* %8
br label %89
54: ; preds = %40
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %10
%57 = load i32, i32* %15
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %56, i32 %57)
%59 = load i32, i32* %9
%60 = call i32 @enable_programming(i32 %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %63, label %62
62: ; preds = %54
store i32 0, i32* %8
br label %89
63: ; preds = %54
%64 = load i32, i32* %13
%65 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
store i32 %64, i32* %65
%66 = load i32, i32* %14
%67 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 1
store i32 %66, i32* %67
%68 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 3
store i32 0, i32* %68
%69 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 2
store i32 0, i32* %69
%70 = load i32, i32* %9
%71 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%72 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%73 = call i32 @do_instruction(i32 %70, i32* %71, i32* %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %76, label %75
75: ; preds = %63
store i32 0, i32* %8
br label %89
76: ; preds = %63
%77 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 3
%78 = load i32, i32* %77
%79 = load i32, i32* %15
%80 = icmp eq i32 %78, %79
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %89
84: ; preds = %76
%85 = load i32, i32* @stderr
%86 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 3
%87 = load i32, i32* %86
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %87)
store i32 0, i32* %8
br label %89
89: ; preds = %84, %81, %75, %62, %53, %35, %29
%90 = load i32, i32* %8
ret i32 %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Not writing %s; already set to 0x%x\0A\00"
@.str.1 = [30 x i8] c"Set %s to 0x%x; verifying... \00"
@.str.2 = [4 x i8] c"ok\0A\00"
@.str.3 = [21 x i8] c"mismatch (got 0x%x)\0A\00"
define i32 @write_config_byte(i32 %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca [4 x i32]
%9 = alloca [4 x i32]
%10 = bitcast [4 x i32]* %8 to i8*
%11 = bitcast [4 x i32]* %9 to i8*
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
store i32 %4, i32* %12
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
store i32 %5, i32* %13
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
store i32 0, i32* %14
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
store i32 0, i32* %15
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%17 = call i32 @do_instruction(i32 %0, i32* %12, i32* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %45, label %19
19: ; preds = %7
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, %6
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %6)
br label %45
26: ; preds = %19
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 0, i32* %15
store i32 %6, i32* %14
%27 = call i32 @do_instruction(i32 %0, i32* %12, i32* %16)
%28 = icmp eq i32 %27, 0
br i1 %28, label %45, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %6)
%32 = call i32 @enable_programming(i32 %0)
%33 = icmp eq i32 %32, 0
br i1 %33, label %45, label %34
34: ; preds = %29
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%35 = call i32 @do_instruction(i32 %0, i32* %12, i32* %16)
%36 = icmp eq i32 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %34
%38 = load i32, i32* %20
%39 = icmp eq i32 %38, %6
%40 = load i32, i32* @stderr
br i1 %39, label %41, label %43
41: ; preds = %37
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %45
43: ; preds = %37
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %45
45: ; preds = %34, %29, %26, %7, %43, %41, %23
%46 = phi i32 [ 1, %23 ], [ 1, %41 ], [ 0, %43 ], [ 0, %7 ], [ 0, %26 ], [ 0, %29 ], [ 0, %34 ]
ret i32 %46
}