#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 atoi(char *);
int getspeed(char *);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setspeed(int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Left fan speed:  %d RPM\n",
           getspeed("/sys/bus/platform/devices/applesmc.768/fan1_min"));
    printf("Right fan speed: %d RPM\n",
           getspeed("/sys/bus/platform/devices/applesmc.768/fan2_min"));
    return 0;
  }
  if (getuid() != 0) {
    printf("You must be root to change the fan speed.\n");
    return 1;
  }
  int fanspeed = atoi(argv[1]);
  setspeed(fanspeed);
  return 0;
}


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)
je     11b4 <main+0x64>
lea    0xea2(%rip),%rdi
call   1060 <getspeed@plt>
mov    %eax,%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xecf(%rip),%rdi
call   1060 <getspeed@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     11df <main+0x8f>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <setspeed@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    118d <main+0x2d>
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     11c9 <main+0x69>
lea    0xf11(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11d9 <main+0x79>
lea    0xe85(%rip),%rdi
call   1070 <getspeed@plt>
lea    0xe60(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeb0(%rip),%rdi
call   1070 <getspeed@plt>
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11d9 <main+0x79>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1040 <setspeed@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Left fan speed: %d RPM\0A\00"
@.str.1 = [48 x i8] c"/sys/bus/platform/devices/applesmc.768/fan1_min\00"
@.str.2 = [25 x i8] c"Right fan speed: %d RPM\0A\00"
@.str.3 = [48 x i8] c"/sys/bus/platform/devices/applesmc.768/fan2_min\00"
@.str.4 = [43 x i8] c"You must be root to change the fan speed.\0A\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 ne i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = call i32 @getspeed(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @getspeed(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 0, i32* %3
br label %26
14: ; preds = %2
%15 = call i64 (...) @getuid()
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %26
19: ; preds = %14
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = call i32 @setspeed(i32 %24)
store i32 0, i32* %3
br label %26
26: ; preds = %19, %17, %9
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [25 x i8] c"Left fan speed: %d RPM\0A\00"
@.str.1 = [48 x i8] c"/sys/bus/platform/devices/applesmc.768/fan1_min\00"
@.str.2 = [25 x i8] c"Right fan speed: %d RPM\0A\00"
@.str.3 = [48 x i8] c"/sys/bus/platform/devices/applesmc.768/fan2_min\00"
@str = [42 x i8] c"You must be root to change the fan speed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 @getspeed(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @getspeed(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %19
9: ; preds = %2
%10 = tail call i64 (...) @getuid()
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %19
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @setspeed(i32 %17)
br label %19
19: ; preds = %14, %12, %4
%20 = phi i32 [ 0, %4 ], [ 1, %12 ], [ 0, %14 ]
ret i32 %20
}