#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dumpregs(int);
int /*<<< orphan*/ dumpstat(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Need spi device\n");
    return 1;
  }
  int fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  dumpstat(argv[1], fd);
  dumpregs(fd);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11dc <main+0x7c>
lea    0xe46(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1060 <dumpstat@plt>
mov    -0x14(%rbp),%edi
call   1030 <dumpregs@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1184 <main+0x24>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11ba <main+0x5a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11c1 <main+0x61>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
mov    %eax,%esi
call   1060 <dumpstat@plt>
mov    %ebp,%edi
call   1030 <dumpregs@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe49(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    11ba <main+0x5a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Need spi device\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %32
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %32
22: ; preds = %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* %6
%27 = call i32 @dumpstat(i8* %25, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @dumpregs(i32 %28)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
br label %32
32: ; preds = %22, %20, %9
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Need spi device\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
15: ; preds = %7
%16 = load i8*, i8** %8
%17 = tail call i32 @dumpstat(i8* %16, i32 %11)
%18 = tail call i32 @dumpregs(i32 %11)
%19 = tail call i32 @close(i32 %11)
br label %20
20: ; preds = %13, %15, %4
%21 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %15 ]
ret i32 %21
}