#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 FS460_get_available_tv_standards(unsigned long *);
int FS460_get_tv_standard(unsigned long *);
int FS460_set_tv_standard(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
char *str_TVStandard(unsigned long);
scalar_t__ strcmp(char *, char *);
void tv_standard(char *mod) {
  int err;
  unsigned long tv_standard, available_tv_standards;
  err = FS460_get_tv_standard(&tv_standard);
  if (err) {
    printf("error %u getting tv standard.\n", err);
    return;
  }
  err = FS460_get_available_tv_standards(&available_tv_standards);
  if (err) {
    printf("error %u getting available tv standards.\n", err);
    return;
  }
  if (available_tv_standards) {
    if (0 == strcmp(mod, "+")) {
      do {
        tv_standard <<= 1;
        if (!tv_standard)
          tv_standard = 1;
      } while (!(tv_standard & available_tv_standards));
    } else if (0 == strcmp(mod, "-")) {
      do {
        tv_standard >>= 1;
        if (!tv_standard)
          tv_standard = 0x80000000;
      } while (!(tv_standard & available_tv_standards));
    } else if (0 != strcmp(mod, "")) {
      printf("Invalid command.\n");
      return;
    }
    err = FS460_set_tv_standard(tv_standard);
    if (err)
      printf("error %u setting TV standard.\n", err);
    else {
      err = FS460_get_tv_standard(&tv_standard);
      if (err)
        printf("error %u getting TV standard after set.\n", err);
      else
        printf("  TV Standard=%s\n", str_TVStandard(tv_standard));
    }
  }
}


x86 assembly (clang, -O0):
<tv_standard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <FS460_get_tv_standard@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1198 <tv_standard+0x38>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1351 <tv_standard+0x1f1>
lea    -0x20(%rbp),%rdi
call   1030 <FS460_get_available_tv_standards@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c4 <tv_standard+0x64>
mov    -0xc(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1351 <tv_standard+0x1f1>
cmpq   $0x0,-0x20(%rbp)
je     1351 <tv_standard+0x1f1>
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1234 <tv_standard+0xd4>
jmp    11f2 <tv_standard+0x92>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1211 <tv_standard+0xb1>
movq   $0x1,-0x18(%rbp)
jmp    1216 <tv_standard+0xb6>
mov    -0x18(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f2 <tv_standard+0x92>
jmp    12d5 <tv_standard+0x175>
mov    -0x8(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    129a <tv_standard+0x13a>
jmp    1257 <tv_standard+0xf7>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1277 <tv_standard+0x117>
mov    $0x80000000,%eax
mov    %rax,-0x18(%rbp)
jmp    127c <tv_standard+0x11c>
mov    -0x18(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1257 <tv_standard+0xf7>
jmp    12d0 <tv_standard+0x170>
mov    -0x8(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12cb <tv_standard+0x16b>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1351 <tv_standard+0x1f1>
jmp    12d0 <tv_standard+0x170>
jmp    12d5 <tv_standard+0x175>
mov    -0x18(%rbp),%rdi
call   1080 <FS460_set_tv_standard@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1301 <tv_standard+0x1a1>
mov    -0xc(%rbp),%esi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    134c <tv_standard+0x1ec>
lea    -0x18(%rbp),%rdi
call   1040 <FS460_get_tv_standard@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     132d <tv_standard+0x1cd>
mov    -0xc(%rbp),%esi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1347 <tv_standard+0x1e7>
mov    -0x18(%rbp),%rdi
call   1060 <str_TVStandard@plt>
mov    %rax,%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    134c <tv_standard+0x1ec>
jmp    1351 <tv_standard+0x1f1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_standard>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1050 <FS460_get_tv_standard@plt>
test   %eax,%eax
je     118d <tv_standard+0x1d>
lea    0xe75(%rip),%rdi
jmp    11a2 <tv_standard+0x32>
lea    0x8(%rsp),%rdi
call   1030 <FS460_get_available_tv_standards@plt>
test   %eax,%eax
je     11b1 <tv_standard+0x41>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
cmpq   $0x0,0x8(%rsp)
je     11ab <tv_standard+0x3b>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1207 <tv_standard+0x97>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     122e <tv_standard+0xbe>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1287 <tv_standard+0x117>
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
jmp    11ab <tv_standard+0x3b>
mov    0x8(%rsp),%rax
mov    (%rsp),%rdi
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
add    %rdi,%rdi
cmove  %rcx,%rdi
test   %rax,%rdi
je     1220 <tv_standard+0xb0>
jmp    1256 <tv_standard+0xe6>
mov    0x8(%rsp),%rax
mov    (%rsp),%rdi
mov    $0x80000000,%ecx
nopl   0x0(%rax)
mov    %rdi,%rdx
shr    %rdx
cmp    $0x2,%rdi
mov    %rdx,%rdi
cmovb  %rcx,%rdi
test   %rax,%rdi
je     1240 <tv_standard+0xd0>
mov    %rdi,(%rsp)
call   1090 <FS460_set_tv_standard@plt>
test   %eax,%eax
je     126f <tv_standard+0xff>
lea    0xde3(%rip),%rdi
jmp    11a2 <tv_standard+0x32>
mov    %rsp,%rdi
call   1050 <FS460_get_tv_standard@plt>
test   %eax,%eax
je     128d <tv_standard+0x11d>
lea    0xdea(%rip),%rdi
jmp    11a2 <tv_standard+0x32>
mov    (%rsp),%rdi
jmp    125a <tv_standard+0xea>
mov    (%rsp),%rdi
call   1070 <str_TVStandard@plt>
lea    0xdf8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11ab <tv_standard+0x3b>

LLVM IR (-O0):
@.str = [31 x i8] c"error %u getting tv standard.\0A\00"
@.str.1 = [42 x i8] c"error %u getting available tv standards.\0A\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [18 x i8] c"Invalid command.\0A\00"
@.str.6 = [31 x i8] c"error %u setting TV standard.\0A\00"
@.str.7 = [41 x i8] c"error %u getting TV standard after set.\0A\00"
@.str.8 = [18 x i8] c" TV Standard=%s\0A\00"
define void @tv_standard(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = call i32 @FS460_get_tv_standard(i64* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %89
12: ; preds = %1
%13 = call i32 @FS460_get_available_tv_standards(i64* %5)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %89
19: ; preds = %12
%20 = load i64, i64* %5
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %89
22: ; preds = %19
%23 = load i8*, i8** %2
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %41
26: ; preds = %22
br label %27
27: ; preds = %34, %26
%28 = load i64, i64* %4
%29 = shl i64 %28, 1
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = icmp ne i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
store i64 1, i64* %4
br label %33
33: ; preds = %32, %27
br label %34
34: ; preds = %33
%35 = load i64, i64* %4
%36 = load i64, i64* %5
%37 = and i64 %35, %36
%38 = icmp ne i64 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %27, label %40
40: ; preds = %34
br label %68
41: ; preds = %22
%42 = load i8*, i8** %2
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 0, %43
br i1 %44, label %45, label %60
45: ; preds = %41
br label %46
46: ; preds = %53, %45
%47 = load i64, i64* %4
%48 = lshr i64 %47, 1
store i64 %48, i64* %4
%49 = load i64, i64* %4
%50 = icmp ne i64 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %46
store i64 2147483648, i64* %4
br label %52
52: ; preds = %51, %46
br label %53
53: ; preds = %52
%54 = load i64, i64* %4
%55 = load i64, i64* %5
%56 = and i64 %54, %55
%57 = icmp ne i64 %56, 0
%58 = xor i1 %57, true
br i1 %58, label %46, label %59
59: ; preds = %53
br label %67
60: ; preds = %41
%61 = load i8*, i8** %2
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%63 = icmp ne i64 0, %62
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %89
66: ; preds = %60
br label %67
67: ; preds = %66, %59
br label %68
68: ; preds = %67, %40
%69 = load i64, i64* %4
%70 = call i32 @FS460_set_tv_standard(i64 %69)
store i32 %70, i32* %3
%71 = load i32, i32* %3
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = load i32, i32* %3
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %74)
br label %88
76: ; preds = %68
%77 = call i32 @FS460_get_tv_standard(i64* %4)
store i32 %77, i32* %3
%78 = load i32, i32* %3
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = load i32, i32* %3
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %81)
br label %87
83: ; preds = %76
%84 = load i64, i64* %4
%85 = call i8* @str_TVStandard(i64 %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %83, %80
br label %88
88: ; preds = %87, %73
br label %89
89: ; preds = %9, %16, %64, %88, %19
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"error %u getting tv standard.\0A\00"
@.str.1 = [42 x i8] c"error %u getting available tv standards.\0A\00"
@.str.2 = [2 x i8] c"+\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.6 = [31 x i8] c"error %u setting TV standard.\0A\00"
@.str.7 = [41 x i8] c"error %u getting TV standard after set.\0A\00"
@.str.8 = [18 x i8] c" TV Standard=%s\0A\00"
@str = [17 x i8] c"Invalid command.\00"
define void @tv_standard(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @FS460_get_tv_standard(i64* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %68
10: ; preds = %1
%11 = call i32 @FS460_get_available_tv_standards(i64* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %68
15: ; preds = %10
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %68, label %18
18: ; preds = %15
%19 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i64, i64* %3
%23 = load i64, i64* %2
br label %24
24: ; preds = %21, %24
%25 = phi i64 [ %23, %21 ], [ %28, %24 ]
%26 = shl i64 %25, 1
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i64 1, i64 %26
%29 = and i64 %28, %22
%30 = icmp eq i64 %29, 0
br i1 %30, label %24, label %51
31: ; preds = %18
%32 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i64, i64* %3
%36 = load i64, i64* %2
br label %37
37: ; preds = %34, %37
%38 = phi i64 [ %36, %34 ], [ %41, %37 ]
%39 = lshr i64 %38, 1
%40 = icmp ult i64 %38, 2
%41 = select i1 %40, i64 2147483648, i64 %39
%42 = and i64 %41, %35
%43 = icmp eq i64 %42, 0
br i1 %43, label %37, label %52
44: ; preds = %31
%45 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load i64, i64* %2
br label %53
49: ; preds = %44
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %68
51: ; preds = %24
store i64 %28, i64* %2
br label %53
52: ; preds = %37
store i64 %41, i64* %2
br label %53
53: ; preds = %47, %52, %51
%54 = phi i64 [ %48, %47 ], [ %41, %52 ], [ %28, %51 ]
%55 = call i32 @FS460_set_tv_standard(i64 %54)
%56 = icmp eq i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %55)
br label %68
59: ; preds = %53
%60 = call i32 @FS460_get_tv_standard(i64* %2)
%61 = icmp eq i32 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %60)
br label %68
64: ; preds = %59
%65 = load i64, i64* %2
%66 = call i8* @str_TVStandard(i64 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %15, %62, %64, %57, %49, %13, %8
ret void
}