#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ system(char *);
void real_change_mode(int mode) {
  char command[256] = "";
  char cmd[256] = "";
  char *cvt_str = 0;
  int com;
  switch (mode) {
  case 0:
    sprintf(command, "gxrandr-switch-mode.sh COMPUTER");
    break;
  case 1:
    sprintf(command, "gxrandr-switch-mode.sh DUPLICATE");
    break;
  case 2:
    sprintf(command, "gxrandr-switch-mode.sh EXTENSION");
    break;
  case 3:
    sprintf(command, "gxrandr-switch-mode.sh PROJECTOR");
    break;
  default:
    sprintf(command, "gxrandr-switch-mode.sh");
    break;
  }
  system(command);
  switch (mode) {
  case 0:
    sprintf(cmd, "echo %d > ~/.gxrandr", 0);
    break;
  case 1:
    sprintf(cmd, "echo %d > ~/.gxrandr", 1);
    break;
  case 2:
    sprintf(cmd, "echo %d > ~/.gxrandr", 2);
    break;
  case 3:
    sprintf(cmd, "echo %d > ~/.gxrandr", 3);
    break;
  }
  system("touch ~/.gxrandr");
  system(cmd);
}


x86 assembly (clang, -O0):
<real_change_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x240(%rbp)
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movaps %xmm0,-0x80(%rbp)
movaps %xmm0,-0x90(%rbp)
movaps %xmm0,-0xa0(%rbp)
movaps %xmm0,-0xb0(%rbp)
movaps %xmm0,-0xc0(%rbp)
movaps %xmm0,-0xd0(%rbp)
movaps %xmm0,-0xe0(%rbp)
movaps %xmm0,-0xf0(%rbp)
movaps %xmm0,-0x100(%rbp)
movaps %xmm0,-0x110(%rbp)
movaps %xmm0,-0x120(%rbp)
movaps %xmm0,-0x130(%rbp)
movaps %xmm0,-0x140(%rbp)
movaps %xmm0,-0x150(%rbp)
movaps %xmm0,-0x160(%rbp)
movaps %xmm0,-0x170(%rbp)
movaps %xmm0,-0x180(%rbp)
movaps %xmm0,-0x190(%rbp)
movaps %xmm0,-0x1a0(%rbp)
movaps %xmm0,-0x1b0(%rbp)
movaps %xmm0,-0x1c0(%rbp)
movaps %xmm0,-0x1d0(%rbp)
movaps %xmm0,-0x1e0(%rbp)
movaps %xmm0,-0x1f0(%rbp)
movaps %xmm0,-0x200(%rbp)
movaps %xmm0,-0x210(%rbp)
movq   $0x0,-0x218(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x228(%rbp)
sub    $0x3,%rax
ja     12a1 <real_change_mode+0x181>
mov    -0x228(%rbp),%rax
lea    0xdd0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x110(%rbp),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12b6 <real_change_mode+0x196>
lea    -0x110(%rbp),%rdi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12b6 <real_change_mode+0x196>
lea    -0x110(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12b6 <real_change_mode+0x196>
lea    -0x110(%rbp),%rdi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12b6 <real_change_mode+0x196>
lea    -0x110(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
mov    %rax,-0x248(%rbp)
sub    $0x3,%rax
ja     1361 <real_change_mode+0x241>
mov    -0x248(%rbp),%rax
lea    0xd2c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x210(%rbp),%rdi
lea    0xdbf(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1361 <real_change_mode+0x241>
lea    -0x210(%rbp),%rdi
lea    0xda3(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1361 <real_change_mode+0x241>
lea    -0x210(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1361 <real_change_mode+0x241>
lea    -0x210(%rbp),%rdi
lea    0xd65(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0xd67(%rip),%rdi
call   1030 <system@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_change_mode>:
sub    $0x208,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
cmp    $0x3,%edi
ja     125d <real_change_mode+0x13d>
mov    %edi,%eax
lea    0xde1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movups 0xdf1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xdd5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
lea    0xe5c(%rip),%rsi
lea    0x100(%rsp),%rdi
xor    %edx,%edx
jmp    1330 <real_change_mode+0x210>
movups 0xe2f(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x68732e65646f6d,%rax
mov    %rax,0xf(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
jmp    1337 <real_change_mode+0x217>
movups 0xdb5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xd99(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
lea    0xdfb(%rip),%rsi
lea    0x100(%rsp),%rdi
mov    $0x1,%edx
jmp    1330 <real_change_mode+0x210>
movups 0xd9c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xd80(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
lea    0xdc1(%rip),%rsi
lea    0x100(%rsp),%rdi
mov    $0x2,%edx
jmp    1330 <real_change_mode+0x210>
movups 0xd83(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xd67(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
mov    %rsp,%rdi
call   1030 <system@plt>
lea    0xd87(%rip),%rsi
lea    0x100(%rsp),%rdi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xd81(%rip),%rdi
call   1030 <system@plt>
lea    0x100(%rsp),%rdi
call   1030 <system@plt>
add    $0x208,%rsp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"gxrandr-switch-mode.sh COMPUTER\00"
@.str.1 = [33 x i8] c"gxrandr-switch-mode.sh DUPLICATE\00"
@.str.2 = [33 x i8] c"gxrandr-switch-mode.sh EXTENSION\00"
@.str.3 = [33 x i8] c"gxrandr-switch-mode.sh PROJECTOR\00"
@.str.4 = [23 x i8] c"gxrandr-switch-mode.sh\00"
@.str.5 = [21 x i8] c"echo %d > ~/.gxrandr\00"
@.str.6 = [17 x i8] c"touch ~/.gxrandr\00"
define void @real_change_mode(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %2
%7 = bitcast [256 x i8]* %3 to i8*
%8 = bitcast [256 x i8]* %4 to i8*
store i8* null, i8** %5
%9 = load i32, i32* %2
switch i32 %9, label %22 [
i32 0, label %10
i32 1, label %13
i32 2, label %16
i32 3, label %19
]
10: ; preds = %1
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %25
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %25
19: ; preds = %1
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %25
22: ; preds = %1
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %22, %19, %16, %13, %10
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 @system(i8* %26)
%28 = load i32, i32* %2
switch i32 %28, label %41 [
i32 0, label %29
i32 1, label %32
i32 2, label %35
i32 3, label %38
]
29: ; preds = %25
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %41
32: ; preds = %25
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %41
35: ; preds = %25
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %41
38: ; preds = %25
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %41
41: ; preds = %25, %38, %35, %32, %29
%42 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%44 = call i32 @system(i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"gxrandr-switch-mode.sh COMPUTER\00"
@.str.1 = [33 x i8] c"gxrandr-switch-mode.sh DUPLICATE\00"
@.str.2 = [33 x i8] c"gxrandr-switch-mode.sh EXTENSION\00"
@.str.3 = [33 x i8] c"gxrandr-switch-mode.sh PROJECTOR\00"
@.str.4 = [23 x i8] c"gxrandr-switch-mode.sh\00"
@.str.5 = [21 x i8] c"echo %d > ~/.gxrandr\00"
@.str.6 = [17 x i8] c"touch ~/.gxrandr\00"
define void @real_change_mode(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
switch i32 %0, label %18 [
i32 0, label %6
i32 1, label %9
i32 2, label %12
i32 3, label %15
]
6: ; preds = %1
%7 = call i32 @system(i8* %4)
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %20
9: ; preds = %1
%10 = call i32 @system(i8* %4)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %20
12: ; preds = %1
%13 = call i32 @system(i8* %4)
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %20
15: ; preds = %1
%16 = call i32 @system(i8* %4)
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %20
18: ; preds = %1
%19 = call i32 @system(i8* %4)
br label %20
20: ; preds = %18, %15, %12, %9, %6
%21 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @system(i8* %5)
ret void
}