#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 */
typedef scalar_t__ uid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ export_gpio(int);
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ set_gpio(int, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int mode;
  uid_t uid = getuid(), euid = geteuid();
  if (uid != 0 || uid != euid || !argv[1]) {
    usage();
    exit(0);
  } else {
    if (strcmp(argv[1], "off") == 0)
      mode = 1;
    else if (strcmp(argv[1], "on") == 0)
      mode = 0;
    else {
      usage();
      exit(0);
    }
    export_gpio(361);
    set_gpio(361, mode);
    printf("Debuging via serial cable on headphone port is %s\r\n", argv[1]);
    return 0;
  }
}


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)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d4 <main+0x54>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11d4 <main+0x54>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11e2 <main+0x62>
mov    $0x0,%al
call   1080 <usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    120c <main+0x8c>
movl   $0x1,-0x14(%rbp)
jmp    1249 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1236 <main+0xb6>
movl   $0x0,-0x14(%rbp)
jmp    1244 <main+0xc4>
mov    $0x0,%al
call   1080 <usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    1249 <main+0xc9>
mov    $0x169,%edi
call   10a0 <export_gpio@plt>
mov    -0x14(%rbp),%esi
mov    $0x169,%edi
call   1030 <set_gpio@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd98(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1060 <geteuid@plt>
or     %rbp,%rax
jne    11cd <main+0x4d>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     11cd <main+0x4d>
lea    0xe54(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11db <main+0x5b>
mov    0x8(%rbx),%rdi
lea    0xe43(%rip),%rsi
call   1070 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11e0 <main+0x60>
xor    %eax,%eax
call   1080 <usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x1,%ebp
mov    $0x169,%edi
call   10a0 <export_gpio@plt>
mov    $0x169,%edi
mov    %ebp,%esi
call   1030 <set_gpio@plt>
mov    0x8(%rbx),%rsi
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"off\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [52 x i8] c"Debuging via serial cable on headphone port is %s\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 (...) @getuid()
store i64 %9, i64* %7
%10 = call i64 (...) @geteuid()
store i64 %10, i64* %8
%11 = load i64, i64* %7
%12 = icmp ne i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %2
%14 = load i64, i64* %7
%15 = load i64, i64* %8
%16 = icmp ne i64 %14, %15
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %17, %13, %2
%23 = call i32 (...) @usage()
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 1, i32* %6
br label %43
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 0, i32* %6
br label %42
39: ; preds = %32
%40 = call i32 (...) @usage()
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %38
br label %43
43: ; preds = %42, %31
%44 = call i32 @export_gpio(i32 361)
%45 = load i32, i32* %6
%46 = call i32 @set_gpio(i32 361, i32 %45)
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"off\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [52 x i8] c"Debuging via serial cable on headphone port is %s\0D\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 (...) @getuid()
%4 = tail call i64 (...) @geteuid()
%5 = icmp eq i64 %3, 0
%6 = icmp eq i64 %4, 0
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8, %2
%13 = tail call i32 (...) @usage()
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %8
%16 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = load i8*, i8** %9
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = tail call i32 (...) @usage()
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %18, %15
%26 = phi i32 [ 1, %15 ], [ 0, %18 ]
%27 = tail call i32 @export_gpio(i32 361)
%28 = tail call i32 @set_gpio(i32 361, i32 %26)
%29 = load i8*, i8** %9
%30 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %29)
ret i32 0
}