#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_vga_position(int *, int *, int *, int *);
int FS460_set_vga_position(int, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void xy_cmd(int cmd, char *mod) {
  int err;
  int left, top, width, height, *p;
  switch (cmd) {
  case 0:
    printf("vga left");
    p = &left;
    break;
  case 1:
    printf("vga top");
    p = &top;
    break;
  case 2:
    printf("vga width");
    p = &width;
    break;
  case 3:
    printf("vga height");
    p = &height;
    break;
  default:
    return;
  }
  err = FS460_get_vga_position(&left, &top, &width, &height);
  if (err) {
    printf(": error %u getting value.\n", err);
    return;
  }
  if (0 == strcmp(mod, "+"))
    *p += 1;
  else if (0 == strcmp(mod, "-"))
    *p -= 1;
  else if (0 == strcmp(mod, "0"))
    *p = 0;
  else if ('\0' != mod[0]) {
    printf(": invalid switch \"%s\".\n", mod);
    return;
  }
  err = FS460_set_vga_position(left, top, width, height);
  if (err)
    printf(": error %u writing value.\n", err);
  else {
    err = FS460_get_vga_position(&left, &top, &width, &height);
  }
  if (err)
    printf(": error %u reading value after write.\n", err);
  else
    printf(" = %d\n", *p);
}


x86 assembly (clang, -O0):
<xy_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x3,%rax
ja     11e0 <xy_cmd+0xa0>
mov    -0x38(%rbp),%rax
lea    0xe95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11e5 <xy_cmd+0xa5>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11e5 <xy_cmd+0xa5>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11e5 <xy_cmd+0xa5>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x24(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11e5 <xy_cmd+0xa5>
jmp    135d <xy_cmd+0x21d>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1060 <FS460_get_vga_position@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     121d <xy_cmd+0xdd>
mov    -0x14(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    135d <xy_cmd+0x21d>
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    124b <xy_cmd+0x10b>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    12dd <xy_cmd+0x19d>
mov    -0x10(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1279 <xy_cmd+0x139>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
jmp    12d8 <xy_cmd+0x198>
mov    -0x10(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a6 <xy_cmd+0x166>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
jmp    12d3 <xy_cmd+0x193>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     12ce <xy_cmd+0x18e>
mov    -0x10(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    135d <xy_cmd+0x21d>
jmp    12d3 <xy_cmd+0x193>
jmp    12d8 <xy_cmd+0x198>
jmp    12dd <xy_cmd+0x19d>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1050 <FS460_set_vga_position@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1311 <xy_cmd+0x1d1>
mov    -0x14(%rbp),%esi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1329 <xy_cmd+0x1e9>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1060 <FS460_get_vga_position@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1349 <xy_cmd+0x209>
mov    -0x14(%rbp),%esi
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    135d <xy_cmd+0x21d>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xy_cmd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
ja     1293 <xy_cmd+0x153>
mov    %rsi,%rbx
mov    %edi,%eax
lea    0x14(%rsp),%r14
lea    0xeaf(%rip),%rdi
mov    %eax,%eax
lea    0xe96(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x10(%rsp),%r14
lea    0xe9a(%rip),%rdi
jmp    119b <xy_cmd+0x5b>
lea    0xc(%rsp),%r14
lea    0xe94(%rip),%rdi
jmp    119b <xy_cmd+0x5b>
lea    0x8(%rsp),%r14
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <FS460_get_vga_position@plt>
test   %eax,%eax
je     11cd <xy_cmd+0x8d>
lea    0xe70(%rip),%rdi
mov    %eax,%esi
jmp    128c <xy_cmd+0x14c>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1225 <xy_cmd+0xe5>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     122c <xy_cmd+0xec>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     129b <xy_cmd+0x15b>
cmpb   $0x0,(%rbx)
je     1237 <xy_cmd+0xf7>
lea    0xe3e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1293 <xy_cmd+0x153>
mov    $0x1,%eax
jmp    1231 <xy_cmd+0xf1>
mov    $0xffffffff,%eax
add    (%r14),%eax
mov    %eax,(%r14)
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
call   1050 <FS460_set_vga_position@plt>
test   %eax,%eax
je     1264 <xy_cmd+0x124>
mov    %eax,%ebx
lea    0xe16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1283 <xy_cmd+0x143>
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <FS460_get_vga_position@plt>
mov    %eax,%ebx
test   %eax,%eax
je     129f <xy_cmd+0x15f>
lea    0xe00(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1234 <xy_cmd+0xf4>
mov    (%r14),%esi
lea    0xe08(%rip),%rdi
jmp    128c <xy_cmd+0x14c>

LLVM IR (-O0):
@.str = [9 x i8] c"vga left\00"
@.str.1 = [8 x i8] c"vga top\00"
@.str.2 = [10 x i8] c"vga width\00"
@.str.3 = [11 x i8] c"vga height\00"
@.str.4 = [27 x i8] c": error %u getting value.\0A\00"
@.str.5 = [2 x i8] c"+\00"
@.str.6 = [2 x i8] c"-\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [24 x i8] c": invalid switch \22%s\22.\0A\00"
@.str.9 = [27 x i8] c": error %u writing value.\0A\00"
@.str.10 = [39 x i8] c": error %u reading value after write.\0A\00"
@.str.11 = [7 x i8] c" = %d\0A\00"
define void @xy_cmd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %3
store i8* %1, i8** %4
%11 = load i32, i32* %3
switch i32 %11, label %20 [
i32 0, label %12
i32 1, label %14
i32 2, label %16
i32 3, label %18
]
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %10
br label %21
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %10
br label %21
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %10
br label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %10
br label %21
20: ; preds = %2
br label %85
21: ; preds = %18, %16, %14, %12
%22 = call i32 @FS460_get_vga_position(i32* %6, i32* %7, i32* %8, i32* %9)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %85
28: ; preds = %21
%29 = load i8*, i8** %4
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i64 0, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32*, i32** %10
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %62
36: ; preds = %28
%37 = load i8*, i8** %4
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%39 = icmp eq i64 0, %38
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32*, i32** %10
%42 = load i32, i32* %41
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %41
br label %61
44: ; preds = %36
%45 = load i8*, i8** %4
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%47 = icmp eq i64 0, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = load i32*, i32** %10
store i32 0, i32* %49
br label %60
50: ; preds = %44
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 0, %54
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = load i8*, i8** %4
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %57)
br label %85
59: ; preds = %50
br label %60
60: ; preds = %59, %48
br label %61
61: ; preds = %60, %40
br label %62
62: ; preds = %61, %32
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = call i32 @FS460_set_vga_position(i32 %63, i32 %64, i32 %65, i32 %66)
store i32 %67, i32* %5
%68 = load i32, i32* %5
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %62
%71 = load i32, i32* %5
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %71)
br label %75
73: ; preds = %62
%74 = call i32 @FS460_get_vga_position(i32* %6, i32* %7, i32* %8, i32* %9)
store i32 %74, i32* %5
br label %75
75: ; preds = %73, %70
%76 = load i32, i32* %5
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32, i32* %5
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0), i32 %79)
br label %85
81: ; preds = %75
%82 = load i32*, i32** %10
%83 = load i32, i32* %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %20, %25, %56, %81, %78
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"vga left\00"
@.str.1 = [8 x i8] c"vga top\00"
@.str.2 = [10 x i8] c"vga width\00"
@.str.3 = [11 x i8] c"vga height\00"
@.str.4 = [27 x i8] c": error %u getting value.\0A\00"
@.str.5 = [2 x i8] c"+\00"
@.str.6 = [2 x i8] c"-\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [24 x i8] c": invalid switch \22%s\22.\0A\00"
@.str.9 = [27 x i8] c": error %u writing value.\0A\00"
@.str.10 = [39 x i8] c": error %u reading value after write.\0A\00"
@.str.11 = [7 x i8] c" = %d\0A\00"
define void @xy_cmd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
switch i32 %0, label %60 [
i32 0, label %14
i32 1, label %11
i32 2, label %12
i32 3, label %13
]
11: ; preds = %2
br label %14
12: ; preds = %2
br label %14
13: ; preds = %2
br label %14
14: ; preds = %2, %13, %12, %11
%15 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = phi i32* [ %6, %13 ], [ %5, %12 ], [ %4, %11 ], [ %3, %2 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %15)
%18 = call i32 @FS460_get_vga_position(i32* %3, i32* %4, i32* %5, i32* %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %60
22: ; preds = %14
%23 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %22
%26 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %25
%29 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %28
%32 = load i8, i8* %1
%33 = icmp eq i8 %32, 0
br i1 %33, label %42, label %34
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %1)
br label %60
36: ; preds = %25, %22
%37 = phi i32 [ 1, %22 ], [ -1, %25 ]
%38 = load i32, i32* %16
%39 = add nsw i32 %38, %37
br label %40
40: ; preds = %36, %28
%41 = phi i32 [ 0, %28 ], [ %39, %36 ]
store i32 %41, i32* %16
br label %42
42: ; preds = %40, %31
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = call i32 @FS460_set_vga_position(i32 %43, i32 %44, i32 %45, i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %47)
br label %54
51: ; preds = %42
%52 = call i32 @FS460_get_vga_position(i32* %3, i32* %4, i32* %5, i32* %6)
%53 = icmp eq i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %49, %51
%55 = phi i32 [ %47, %49 ], [ %52, %51 ]
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0), i32 %55)
br label %60
57: ; preds = %51
%58 = load i32, i32* %16
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %54, %57, %2, %34, %20
ret void
}