#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
void change_speed(int speed) {
  char tmp_string[60] = {0};
  char speed_string[5] = {0};
  switch (speed) {
  case 10:
    strcpy(speed_string, "auto");
    break;
  case 0:
    strcpy(speed_string, "0");
    break;
  default:
    fprintf(stderr, "Error in change_speed");
  }
  sprintf(tmp_string, "echo level %s > /proc/acpi/ibm/fan", speed_string);
  system(tmp_string);
  printf("Speed level has been changed to %s\n", speed_string);
}


x86 assembly (clang, -O0):
<change_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movups %xmm0,-0x14(%rbp)
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movb   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
test   %eax,%eax
je     11b2 <change_speed+0x62>
jmp    118c <change_speed+0x3c>
mov    -0x4c(%rbp),%eax
sub    $0xa,%eax
jne    11c7 <change_speed+0x77>
jmp    119d <change_speed+0x4d>
lea    -0x48(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11dc <change_speed+0x8c>
lea    -0x48(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11dc <change_speed+0x8c>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <system@plt>
lea    -0x48(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_speed>:
push   %r14
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x3c(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
test   %edi,%edi
je     118d <change_speed+0x3d>
cmp    $0xa,%edi
jne    11a0 <change_speed+0x50>
lea    0xe75(%rip),%rsi
jmp    1194 <change_speed+0x44>
lea    0xe71(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strcpy@plt>
jmp    11b5 <change_speed+0x65>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe61(%rip),%rsi
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"auto\00"
@.str.1 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error in change_speed\00"
@.str.3 = [35 x i8] c"echo level %s > /proc/acpi/ibm/fan\00"
@.str.4 = [36 x i8] c"Speed level has been changed to %s\0A\00"
define void @change_speed(i32 %0) {
%2 = alloca i32
%3 = alloca [60 x i8]
%4 = alloca [5 x i8]
store i32 %0, i32* %2
%5 = bitcast [60 x i8]* %3 to i8*
%6 = bitcast [5 x i8]* %4 to i8*
%7 = load i32, i32* %2
switch i32 %7, label %14 [
i32 10, label %8
i32 0, label %11
]
8: ; preds = %1
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
11: ; preds = %1
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %14, %11, %8
%18 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"auto\00"
@.str.1 = [2 x i8] c"0\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Error in change_speed\00"
@.str.3 = [35 x i8] c"echo level %s > /proc/acpi/ibm/fan\00"
@.str.4 = [36 x i8] c"Speed level has been changed to %s\0A\00"
define void @change_speed(i32 %0) {
%2 = alloca [60 x i8]
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
switch i32 %0, label %10 [
i32 10, label %6
i32 0, label %8
]
6: ; preds = %1
%7 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %10, %8, %6
%14 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%15 = call i32 @system(i8* %4)
%16 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %5)
ret void
}