#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ output_adcs(long, long, int *);
int /*<<< orphan*/ restore_io();
int /*<<< orphan*/ setup_gpio(long);
int /*<<< orphan*/ setup_io();
int /*<<< orphan*/ setup_spi();
long strtol(char *, char **, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int sent;
  char *end;
  long chip_select, channel;
  chip_select = -1;
  channel = -1;
  switch (argc) {
  case 3:
    channel = strtol(argv[2], &end, 10);
    if (*end || channel < 0 || channel > 1)
      usage(argv[0]);
  case 2:
    chip_select = strtol(argv[1], &end, 10);
    if (*end || chip_select < 0 || chip_select > 1)
      usage(argv[0]);
    break;
  case 1:
    break;
  default:
    usage(argv[0]);
  }
  setup_io();
  setup_gpio(chip_select);
  setup_spi();
  sent = 0;
  output_adcs(chip_select, channel, &sent);
  restore_io();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
movq   $0xffffffffffffffff,-0x30(%rbp)
ff
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     127e <main+0xfe>
jmp    11ba <main+0x3a>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     122d <main+0xad>
jmp    11cb <main+0x4b>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
jne    1283 <main+0x103>
jmp    11dc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    121c <main+0x9c>
cmpq   $0x0,-0x30(%rbp)
jl     121c <main+0x9c>
cmpq   $0x1,-0x30(%rbp)
jle    1228 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    122d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    126d <main+0xed>
cmpq   $0x0,-0x28(%rbp)
jl     126d <main+0xed>
cmpq   $0x1,-0x28(%rbp)
jle    1279 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    128f <main+0x10f>
jmp    128f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    $0x0,%al
call   1090 <setup_io@plt>
mov    -0x28(%rbp),%rdi
call   1030 <setup_gpio@plt>
mov    $0x0,%al
call   1040 <setup_spi@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <output_adcs@plt>
mov    $0x0,%al
call   10a0 <restore_io@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffffffffffff,%rbx
cmp    $0x1,%edi
je     120b <main+0x8b>
mov    %rsi,%r14
mov    $0xffffffffffffffff,%r15
cmp    $0x2,%edi
je     11d9 <main+0x59>
cmp    $0x3,%edi
jne    1201 <main+0x81>
mov    0x10(%r14),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r15
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    11d1 <main+0x51>
test   %r15,%r15
js     11d1 <main+0x51>
cmp    $0x2,%r15
jl     11d9 <main+0x59>
mov    (%r14),%rdi
call   1060 <usage@plt>
mov    0x8(%r14),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1201 <main+0x81>
test   %rbx,%rbx
js     1201 <main+0x81>
cmp    $0x2,%rbx
jl     1212 <main+0x92>
mov    (%r14),%rdi
call   1060 <usage@plt>
jmp    1212 <main+0x92>
mov    $0xffffffffffffffff,%r15
xor    %eax,%eax
call   1090 <setup_io@plt>
mov    %rbx,%rdi
call   1030 <setup_gpio@plt>
xor    %eax,%eax
call   1040 <setup_spi@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <output_adcs@plt>
xor    %eax,%eax
call   10a0 <restore_io@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %8
store i64 -1, i64* %9
%10 = load i32, i32* %4
switch i32 %10, label %54 [
i32 3, label %11
i32 2, label %32
i32 1, label %53
]
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i8** %7, i32 10)
store i64 %15, i64* %9
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %11
%21 = load i64, i64* %9
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i64, i64* %9
%25 = icmp sgt i64 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %23, %20, %11
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @usage(i8* %29)
br label %31
31: ; preds = %26, %23
br label %32
32: ; preds = %2, %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strtol(i8* %35, i8** %7, i32 10)
store i64 %36, i64* %8
%37 = load i8*, i8** %7
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %32
%42 = load i64, i64* %8
%43 = icmp slt i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i64, i64* %8
%46 = icmp sgt i64 %45, 1
br i1 %46, label %47, label %52
47: ; preds = %44, %41, %32
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @usage(i8* %50)
br label %52
52: ; preds = %47, %44
br label %59
53: ; preds = %2
br label %59
54: ; preds = %2
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = call i32 @usage(i8* %57)
br label %59
59: ; preds = %54, %53, %52
%60 = call i32 (...) @setup_io()
%61 = load i64, i64* %8
%62 = call i32 @setup_gpio(i64 %61)
%63 = call i32 (...) @setup_spi()
store i32 0, i32* %6
%64 = load i64, i64* %8
%65 = load i64, i64* %9
%66 = call i32 @output_adcs(i64 %64, i64 %65, i32* %6)
%67 = call i32 (...) @restore_io()
%68 = load i32, i32* @EXIT_SUCCESS
%69 = call i32 @exit(i32 %68)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast i8** %4 to i8*
switch i32 %0, label %33 [
i32 3, label %7
i32 2, label %21
i32 1, label %38
]
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = call i64 @strtol(i8* %9, i8** %4, i32 10)
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
%14 = icmp slt i64 %10, 0
%15 = select i1 %13, i1 true, i1 %14
%16 = icmp sgt i64 %10, 1
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = load i8*, i8** %1
%20 = tail call i32 @usage(i8* %19)
br label %21
21: ; preds = %18, %7, %2
%22 = phi i64 [ -1, %2 ], [ %10, %18 ], [ %10, %7 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strtol(i8* %24, i8** %4, i32 10)
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
%29 = icmp slt i64 %25, 0
%30 = select i1 %28, i1 true, i1 %29
%31 = icmp sgt i64 %25, 1
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %33, label %38
33: ; preds = %2, %21
%34 = phi i64 [ %25, %21 ], [ -1, %2 ]
%35 = phi i64 [ %22, %21 ], [ -1, %2 ]
%36 = load i8*, i8** %1
%37 = tail call i32 @usage(i8* %36)
br label %38
38: ; preds = %33, %21, %2
%39 = phi i64 [ -1, %2 ], [ %25, %21 ], [ %34, %33 ]
%40 = phi i64 [ -1, %2 ], [ %22, %21 ], [ %35, %33 ]
%41 = tail call i32 (...) @setup_io()
%42 = tail call i32 @setup_gpio(i64 %39)
%43 = tail call i32 (...) @setup_spi()
store i32 0, i32* %3
%44 = call i32 @output_adcs(i64 %39, i64 %40, i32* %3)
%45 = call i32 (...) @restore_io()
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @exit(i32 %46)
unreachable
}