#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*/ restore_io();
int /*<<< orphan*/ setup_gpio(long);
int /*<<< orphan*/ setup_io();
int /*<<< orphan*/ setup_spi();
void *strtol(char *, char **, int);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ write_dac(long, long, int);
int main(int argc, char *argv[]) {
  char *end;
  long chip_select, channel;
  int value;
  if (argc != 4)
    usage(argv[0]);
  chip_select = strtol(argv[1], &end, 10);
  if (*end || chip_select < 0 || chip_select > 1)
    usage(argv[0]);
  channel = strtol(argv[2], &end, 10);
  if (*end || channel < 0 || channel > 1)
    usage(argv[0]);
  value = strtol(argv[3], &end, 10);
  if (*end || value < 0 || value > 4095)
    usage(argv[0]);
  setup_io();
  setup_gpio(chip_select);
  setup_spi();
  write_dac(chip_select, channel, value);
  restore_io();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11ac <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ec <main+0x6c>
cmpq   $0x0,-0x20(%rbp)
jl     11ec <main+0x6c>
cmpq   $0x1,-0x20(%rbp)
jle    11f8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1238 <main+0xb8>
cmpq   $0x0,-0x28(%rbp)
jl     1238 <main+0xb8>
cmpq   $0x1,-0x28(%rbp)
jle    1244 <main+0xc4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1284 <main+0x104>
cmpl   $0x0,-0x2c(%rbp)
jl     1284 <main+0x104>
cmpl   $0xfff,-0x2c(%rbp)
jle    1290 <main+0x110>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    $0x0,%al
call   1090 <setup_io@plt>
mov    -0x20(%rbp),%rdi
call   1030 <setup_gpio@plt>
mov    $0x0,%al
call   1050 <setup_spi@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write_dac@plt>
mov    $0x0,%al
call   10a0 <restore_io@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x4,%edi
je     1199 <main+0x19>
mov    (%r12),%rdi
call   1070 <usage@plt>
mov    0x8(%r12),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c2 <main+0x42>
test   %r14,%r14
js     11c2 <main+0x42>
cmp    $0x2,%r14
jl     11cb <main+0x4b>
mov    (%r12),%rdi
call   1070 <usage@plt>
mov    0x10(%r12),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%r15
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    11f4 <main+0x74>
test   %r15,%r15
js     11f4 <main+0x74>
cmp    $0x2,%r15
jl     11fd <main+0x7d>
mov    (%r12),%rdi
call   1070 <usage@plt>
mov    0x18(%r12),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1227 <main+0xa7>
test   %ebx,%ebx
js     1227 <main+0xa7>
cmp    $0x1000,%ebx
jl     1230 <main+0xb0>
mov    (%r12),%rdi
call   1070 <usage@plt>
xor    %eax,%eax
call   1090 <setup_io@plt>
mov    %r14,%rdi
call   1030 <setup_gpio@plt>
xor    %eax,%eax
call   1050 <setup_spi@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <write_dac@plt>
xor    %eax,%eax
call   10a0 <restore_io@plt>
mov    0x2d7f(%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 i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
br label %17
17: ; preds = %12, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @strtol(i8* %20, i8** %6, i32 10)
%22 = ptrtoint i8* %21 to i64
store i64 %22, i64* %7
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %17
%28 = load i64, i64* %7
%29 = icmp slt i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i64, i64* %7
%32 = icmp sgt i64 %31, 1
br i1 %32, label %33, label %38
33: ; preds = %30, %27, %17
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @usage(i8* %36)
br label %38
38: ; preds = %33, %30
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i8* @strtol(i8* %41, i8** %6, i32 10)
%43 = ptrtoint i8* %42 to i64
store i64 %43, i64* %8
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %38
%49 = load i64, i64* %8
%50 = icmp slt i64 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i64, i64* %8
%53 = icmp sgt i64 %52, 1
br i1 %53, label %54, label %59
54: ; preds = %51, %48, %38
%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, %51
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
%63 = call i8* @strtol(i8* %62, i8** %6, i32 10)
%64 = ptrtoint i8* %63 to i32
store i32 %64, i32* %9
%65 = load i8*, i8** %6
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 0
br i1 %68, label %75, label %69
69: ; preds = %59
%70 = load i32, i32* %9
%71 = icmp slt i32 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %69
%73 = load i32, i32* %9
%74 = icmp sgt i32 %73, 4095
br i1 %74, label %75, label %80
75: ; preds = %72, %69, %59
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 0
%78 = load i8*, i8** %77
%79 = call i32 @usage(i8* %78)
br label %80
80: ; preds = %75, %72
%81 = call i32 (...) @setup_io()
%82 = load i64, i64* %7
%83 = call i32 @setup_gpio(i64 %82)
%84 = call i32 (...) @setup_spi()
%85 = load i64, i64* %7
%86 = load i64, i64* %8
%87 = load i32, i32* %9
%88 = call i32 @write_dac(i64 %85, i64 %86, i32 %87)
%89 = call i32 (...) @restore_io()
%90 = load i32, i32* @EXIT_SUCCESS
%91 = call i32 @exit(i32 %90)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i8* @strtol(i8* %11, i8** %3, i32 10)
%13 = ptrtoint i8* %12 to i64
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = icmp slt i8* %12, null
%18 = select i1 %16, i1 true, i1 %17
%19 = icmp sgt i8* %12, inttoptr (i64 1 to i8*)
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = load i8*, i8** %1
%23 = tail call i32 @usage(i8* %22)
br label %24
24: ; preds = %9, %21
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = call i8* @strtol(i8* %26, i8** %3, i32 10)
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
%31 = icmp slt i8* %27, null
%32 = select i1 %30, i1 true, i1 %31
%33 = icmp sgt i8* %27, inttoptr (i64 1 to i8*)
%34 = select i1 %32, i1 true, i1 %33
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = load i8*, i8** %1
%37 = tail call i32 @usage(i8* %36)
br label %38
38: ; preds = %24, %35
%39 = getelementptr inbounds i8*, i8** %1, i64 3
%40 = load i8*, i8** %39
%41 = call i8* @strtol(i8* %40, i8** %3, i32 10)
%42 = ptrtoint i8* %41 to i64
%43 = trunc i64 %42 to i32
%44 = load i8*, i8** %3
%45 = load i8, i8* %44
%46 = icmp ne i8 %45, 0
%47 = icmp slt i32 %43, 0
%48 = select i1 %46, i1 true, i1 %47
%49 = icmp sgt i32 %43, 4095
%50 = select i1 %48, i1 true, i1 %49
br i1 %50, label %51, label %54
51: ; preds = %38
%52 = load i8*, i8** %1
%53 = tail call i32 @usage(i8* %52)
br label %54
54: ; preds = %38, %51
%55 = ptrtoint i8* %27 to i64
%56 = tail call i32 (...) @setup_io()
%57 = tail call i32 @setup_gpio(i64 %13)
%58 = tail call i32 (...) @setup_spi()
%59 = tail call i32 @write_dac(i64 %13, i64 %55, i32 %43)
%60 = tail call i32 (...) @restore_io()
%61 = load i32, i32* @EXIT_SUCCESS
%62 = tail call i32 @exit(i32 %61)
unreachable
}