#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 */
char *cm108_find_device();
int cm108_open(char const *);
int /*<<< orphan*/ cm108_ptt_set(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  const char *path;
  path = cm108_find_device();
  if (!path) {
    printf("No device found. Sorry.\n");
    return 1;
  }
  printf("Found device %s\n", path);
  int fd = cm108_open(path);
  if (fd == -1) {
    printf("\nCould not open device! Have you installed the udev rules?\n");
    printf("You can retry as root.\n");
    exit(3);
  }
  printf("\nEnabling PTT...\n");
  cm108_ptt_set(fd, 1);
  sleep(1);
  printf("Disabling PTT...\n");
  cm108_ptt_set(fd, 0);
  printf("\nIf the RED led was on and is now off the PTT function works.\n");
}


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)
mov    $0x0,%al
call   1040 <cm108_find_device@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <main+0x46>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <main+0xdf>
mov    -0x18(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <cm108_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11f4 <main+0x94>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3,%edi
call   1070 <exit@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1060 <cm108_ptt_set@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1060 <cm108_ptt_set@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <cm108_find_device@plt>
test   %rax,%rax
je     11e4 <main+0x74>
mov    %rax,%rbp
lea    0xe77(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1060 <cm108_open@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x8e>
mov    %eax,%ebp
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <cm108_ptt_set@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <cm108_ptt_set@plt>
lea    0xe69(%rip),%rdi
jmp    11f0 <main+0x80>
mov    $0x1,%ebx
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"No device found. Sorry.\0A\00"
@.str.1 = [17 x i8] c"Found device %s\0A\00"
@.str.2 = [60 x i8] c"\0ACould not open device! Have you installed the udev rules?\0A\00"
@.str.3 = [24 x i8] c"You can retry as root.\0A\00"
@.str.4 = [18 x i8] c"\0AEnabling PTT...\0A\00"
@.str.5 = [18 x i8] c"Disabling PTT...\0A\00"
@.str.6 = [63 x i8] c"\0AIf the RED led was on and is now off the PTT function works.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* (...) @cm108_find_device()
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %6
%17 = call i32 @cm108_open(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 3)
unreachable
24: ; preds = %13
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* %7
%27 = call i32 @cm108_ptt_set(i32 %26, i32 1)
%28 = call i32 @sleep(i32 1)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* %7
%31 = call i32 @cm108_ptt_set(i32 %30, i32 0)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %24, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Found device %s\0A\00"
@str = [24 x i8] c"No device found. Sorry.\00"
@str.7 = [17 x i8] c"\0AEnabling PTT...\00"
@str.8 = [17 x i8] c"Disabling PTT...\00"
@str.9 = [62 x i8] c"\0AIf the RED led was on and is now off the PTT function works.\00"
@str.10 = [59 x i8] c"\0ACould not open device! Have you installed the udev rules?\00"
@str.11 = [23 x i8] c"You can retry as root.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* (...) @cm108_find_device()
%4 = icmp eq i8* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = tail call i32 @cm108_open(i8* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%12 = tail call i32 @exit(i32 3)
unreachable
13: ; preds = %5
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%15 = tail call i32 @cm108_ptt_set(i32 %7, i32 1)
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%18 = tail call i32 @cm108_ptt_set(i32 %7, i32 0)
br label %19
19: ; preds = %2, %13
%20 = phi i8* [ getelementptr inbounds ([62 x i8], [62 x i8]* @str.9, i64 0, i64 0), %13 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0), %2 ]
%21 = phi i32 [ 0, %13 ], [ 1, %2 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) %20)
ret i32 %21
}