#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__ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ restore_io();
int /*<<< orphan*/ setup_gpio();
int /*<<< orphan*/ setup_io();
int /*<<< orphan*/ setup_spi();
int /*<<< orphan*/ write_dac(int, int);
void main(void) {
  int d, chan, dummy;
  do {
    printf("Which channel do you want to test? Type 0 or 1.\n");
    chan = (int)getchar();
    (void)getchar();
  } while (chan != '0' && chan != '1');
  chan = chan - '0';
  printf("These are the connections for the digital to analogue test:\n");
  printf("jumper connecting GP11 to SCLK\n");
  printf("jumper connecting GP10 to MOSI\n");
  printf("jumper connecting GP9 to MISO\n");
  printf("jumper connecting GP7 to CSnB\n");
  printf("Multimeter connections (set your meter to read V DC):\n");
  printf("  connect black probe to GND\n");
  printf("  connect red probe to DA%d on J29\n", chan);
  printf("When ready hit enter.\n");
  (void)getchar();
  setup_io();
  setup_gpio();
  setup_spi();
  d = 0x000;
  write_dac(chan, d);
  printf("Your meter should read about 0V\n");
  printf("When ready hit enter.\n");
  (void)getchar();
  d = 0x400;
  write_dac(chan, d);
  printf("Your meter should read about 0.5V\n");
  printf("When ready hit enter.\n");
  (void)getchar();
  d = 0x7F0;
  write_dac(chan, d);
  printf("Your meter should read about 1.02V\n");
  printf("When ready hit enter.\n");
  (void)getchar();
  d = 0xAA0;
  write_dac(chan, d);
  printf("Your meter should read about 1.36V\n");
  printf("When ready hit enter.\n");
  (void)getchar();
  d = 0xFF0;
  write_dac(chan, d);
  printf("Your meter should read about 2.04V\n");
  printf("When ready hit enter.\n");
  (void)getchar();
  restore_io();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
cmpl   $0x30,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     11b0 <main+0x40>
cmpl   $0x31,-0x8(%rbp)
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1178 <main+0x8>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xf11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1080 <setup_io@plt>
mov    $0x0,%al
call   1030 <setup_gpio@plt>
mov    $0x0,%al
call   1070 <setup_spi@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <write_dac@plt>
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x400,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <write_dac@plt>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x7f0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <write_dac@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0xaa0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <write_dac@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0xff0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <write_dac@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1090 <restore_io@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe99(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%eax
and    $0xfffffffe,%eax
cmp    $0x30,%eax
jne    1190 <main+0x10>
add    $0xffffffd0,%ebx
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
lea    0xeed(%rip),%rdi
call   1040 <puts@plt>
lea    0xeff(%rip),%rdi
call   1040 <puts@plt>
lea    0xf11(%rip),%rdi
call   1040 <puts@plt>
lea    0xf3b(%rip),%rdi
call   1040 <puts@plt>
lea    0xdef(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xfe7(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1090 <setup_io@plt>
xor    %eax,%eax
call   1030 <setup_gpio@plt>
xor    %eax,%eax
call   1080 <setup_spi@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <write_dac@plt>
lea    0xf08(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   1060 <write_dac@plt>
lea    0xf01(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%edi
mov    $0x7f0,%esi
call   1060 <write_dac@plt>
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%edi
mov    $0xaa0,%esi
call   1060 <write_dac@plt>
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%edi
mov    $0xff0,%esi
call   1060 <write_dac@plt>
lea    0xef4(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <restore_io@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Which channel do you want to test? Type 0 or 1.\0A\00"
@.str.1 = [61 x i8] c"These are the connections for the digital to analogue test:\0A\00"
@.str.2 = [32 x i8] c"jumper connecting GP11 to SCLK\0A\00"
@.str.3 = [32 x i8] c"jumper connecting GP10 to MOSI\0A\00"
@.str.4 = [31 x i8] c"jumper connecting GP9 to MISO\0A\00"
@.str.5 = [31 x i8] c"jumper connecting GP7 to CSnB\0A\00"
@.str.6 = [55 x i8] c"Multimeter connections (set your meter to read V DC):\0A\00"
@.str.7 = [30 x i8] c" connect black probe to GND\0A\00"
@.str.8 = [36 x i8] c" connect red probe to DA%d on J29\0A\00"
@.str.9 = [23 x i8] c"When ready hit enter.\0A\00"
@.str.10 = [33 x i8] c"Your meter should read about 0V\0A\00"
@.str.11 = [35 x i8] c"Your meter should read about 0.5V\0A\00"
@.str.12 = [36 x i8] c"Your meter should read about 1.02V\0A\00"
@.str.13 = [36 x i8] c"Your meter should read about 1.36V\0A\00"
@.str.14 = [36 x i8] c"Your meter should read about 2.04V\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
br label %4
4: ; preds = %15, %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%6 = call i64 (...) @getchar()
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
%8 = call i64 (...) @getchar()
br label %9
9: ; preds = %4
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 48
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 49
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ false, %9 ], [ %14, %12 ]
br i1 %16, label %4, label %17
17: ; preds = %15
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 48
store i32 %19, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%30 = call i64 (...) @getchar()
%31 = call i32 (...) @setup_io()
%32 = call i32 (...) @setup_gpio()
%33 = call i32 (...) @setup_spi()
store i32 0, i32* %1
%34 = load i32, i32* %2
%35 = load i32, i32* %1
%36 = call i32 @write_dac(i32 %34, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%39 = call i64 (...) @getchar()
store i32 1024, i32* %1
%40 = load i32, i32* %2
%41 = load i32, i32* %1
%42 = call i32 @write_dac(i32 %40, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%45 = call i64 (...) @getchar()
store i32 2032, i32* %1
%46 = load i32, i32* %2
%47 = load i32, i32* %1
%48 = call i32 @write_dac(i32 %46, i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%51 = call i64 (...) @getchar()
store i32 2720, i32* %1
%52 = load i32, i32* %2
%53 = load i32, i32* %1
%54 = call i32 @write_dac(i32 %52, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0))
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%57 = call i64 (...) @getchar()
store i32 4080, i32* %1
%58 = load i32, i32* %2
%59 = load i32, i32* %1
%60 = call i32 @write_dac(i32 %58, i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%63 = call i64 (...) @getchar()
%64 = call i32 (...) @restore_io()
ret void
}

LLVM IR (-O2):
@.str.8 = [36 x i8] c" connect red probe to DA%d on J29\0A\00"
@str = [48 x i8] c"Which channel do you want to test? Type 0 or 1.\00"
@str.15 = [60 x i8] c"These are the connections for the digital to analogue test:\00"
@str.16 = [31 x i8] c"jumper connecting GP11 to SCLK\00"
@str.17 = [31 x i8] c"jumper connecting GP10 to MOSI\00"
@str.18 = [30 x i8] c"jumper connecting GP9 to MISO\00"
@str.19 = [30 x i8] c"jumper connecting GP7 to CSnB\00"
@str.20 = [54 x i8] c"Multimeter connections (set your meter to read V DC):\00"
@str.21 = [29 x i8] c" connect black probe to GND\00"
@str.23 = [32 x i8] c"Your meter should read about 0V\00"
@str.25 = [34 x i8] c"Your meter should read about 0.5V\00"
@str.27 = [35 x i8] c"Your meter should read about 1.02V\00"
@str.29 = [35 x i8] c"Your meter should read about 1.36V\00"
@str.31 = [35 x i8] c"Your meter should read about 2.04V\00"
@str.32 = [22 x i8] c"When ready hit enter.\00"
define void @main() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%3 = tail call i64 (...) @getchar()
%4 = tail call i64 (...) @getchar()
%5 = and i64 %3, 4294967294
%6 = icmp eq i64 %5, 48
br i1 %6, label %7, label %1
7: ; preds = %1
%8 = trunc i64 %3 to i32
%9 = add nsw i32 %8, -48
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.16, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.17, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.18, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.19, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.20, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %9)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%19 = tail call i64 (...) @getchar()
%20 = tail call i32 (...) @setup_io()
%21 = tail call i32 (...) @setup_gpio()
%22 = tail call i32 (...) @setup_spi()
%23 = tail call i32 @write_dac(i32 %9, i32 0)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.23, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%26 = tail call i64 (...) @getchar()
%27 = tail call i32 @write_dac(i32 %9, i32 1024)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.25, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%30 = tail call i64 (...) @getchar()
%31 = tail call i32 @write_dac(i32 %9, i32 2032)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.27, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%34 = tail call i64 (...) @getchar()
%35 = tail call i32 @write_dac(i32 %9, i32 2720)
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.29, i64 0, i64 0))
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%38 = tail call i64 (...) @getchar()
%39 = tail call i32 @write_dac(i32 %9, i32 4080)
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.31, i64 0, i64 0))
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.32, i64 0, i64 0))
%42 = tail call i64 (...) @getchar()
%43 = tail call i32 (...) @restore_io()
ret void
}