#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 ProcessCommand(char *, char *);
int atoi(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int ReadInputMode(char ret[]) {
  char *input = NULL;
  int err;
  if (!(err = ProcessCommand(ret, "CR1\r"))) {
    switch (atoi((char *)ret)) {
    case 0:
      input = "composit";
      break;
    case 1:
      input = "s-video";
      break;
    case 2:
      input = "component 1";
      break;
    case 3:
      input = "component 2";
      break;
    case 4:
      input = "hdmi";
      break;
    case 5:
      input = "vga";
      break;
    case 6:
      input = "scart";
      break;
    }
    strcpy(ret, input);
  }
  return (err);
}


x86 assembly (clang, -O0):
<ReadInputMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1040 <ProcessCommand@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1204 <ReadInputMode+0xd4>
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     11f7 <ReadInputMode+0xc7>
mov    -0x20(%rbp),%rax
lea    0xe7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8e(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe87(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe7f(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe7b(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe77(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe6c(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11f7 <ReadInputMode+0xc7>
lea    0xe60(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadInputMode>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
call   1040 <ProcessCommand@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1171 <ReadInputMode+0x41>
mov    %rbx,%rdi
call   1050 <atoi@plt>
cmp    $0x6,%eax
ja     1167 <ReadInputMode+0x37>
cltq
lea    0xee2(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    1169 <ReadInputMode+0x39>
xor    %esi,%esi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"CR1\0D\00"
@.str.1 = [9 x i8] c"composit\00"
@.str.2 = [8 x i8] c"s-video\00"
@.str.3 = [12 x i8] c"component 1\00"
@.str.4 = [12 x i8] c"component 2\00"
@.str.5 = [5 x i8] c"hdmi\00"
@.str.6 = [4 x i8] c"vga\00"
@.str.7 = [6 x i8] c"scart\00"
define i32 @ReadInputMode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i32 @ProcessCommand(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @atoi(i8* %9)
switch i32 %10, label %18 [
i32 0, label %11
i32 1, label %12
i32 2, label %13
i32 3, label %14
i32 4, label %15
i32 5, label %16
i32 6, label %17
]
11: ; preds = %8
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %18
12: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %18
13: ; preds = %8
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %18
14: ; preds = %8
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %18
15: ; preds = %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %18
16: ; preds = %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %18
17: ; preds = %8
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %18
18: ; preds = %8, %17, %16, %15, %14, %13, %12, %11
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
br label %22
22: ; preds = %18, %1
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"CR1\0D\00"
@.str.1 = [9 x i8] c"composit\00"
@.str.2 = [8 x i8] c"s-video\00"
@.str.3 = [12 x i8] c"component 1\00"
@.str.4 = [12 x i8] c"component 2\00"
@.str.5 = [5 x i8] c"hdmi\00"
@.str.6 = [4 x i8] c"vga\00"
@.str.7 = [6 x i8] c"scart\00"
@reltable.ReadInputMode = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([7 x i32]* @reltable.ReadInputMode to i64)) to i32)]
define i32 @ReadInputMode(i8* %0) {
%2 = tail call i32 @ProcessCommand(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = tail call i32 @atoi(i8* %0)
%6 = icmp ult i32 %5, 7
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.ReadInputMode to i8*), i64 %9)
br label %11
11: ; preds = %7, %4
%12 = phi i8* [ null, %4 ], [ %10, %7 ]
%13 = tail call i32 @strcpy(i8* %0, i8* %12)
br label %14
14: ; preds = %11, %1
ret i32 %2
}