#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 */
typedef int uint8_t;
typedef int uint32_t;
typedef int int32_t;

/* Variables and functions */
char get_screen_cache(int, int);
int /*<<< orphan*/ set_screen_cache(int, int, char);
void control_ball() {
  typedef struct {
    uint32_t x;
    uint32_t y;
    int32_t vx;
    int32_t vy;
    char c;
  } ball_t;
  static ball_t s_ball;
  static uint8_t s_first_flag = 1;
  if (s_first_flag == 1) {
    s_ball.x = 6;
    s_ball.y = 4;
    s_ball.vx = 1;
    s_ball.vy = -1;
    s_ball.c = '*';
    s_first_flag = 0;
  }
  s_ball.x += s_ball.vx;
  s_ball.y += s_ball.vy;
  if (get_screen_cache(s_ball.x + s_ball.vx, s_ball.y) != ' ')
    s_ball.vx *= -1;
  if (get_screen_cache(s_ball.x, s_ball.y + s_ball.vy) != ' ')
    s_ball.vy *= -1;
  set_screen_cache(s_ball.x, s_ball.y, s_ball.c);
}


x86 assembly (clang, -O0):
<control_ball>:
push   %rbp
mov    %rsp,%rbp
cmpl   $0x1,0x2f05(%rip)
jne    116a <control_ball+0x4a>
movl   $0x6,0x2efd(%rip)
movl   $0x4,0x2ef7(%rip)
movl   $0x1,0x2ef1(%rip)
movl   $0xffffffff,0x2eeb(%rip)
ff ff ff
movb   $0x2a,0x2ee8(%rip)
movl   $0x0,0x2ec6(%rip)
mov    0x2ed0(%rip),%eax
add    0x2ec2(%rip),%eax
mov    %eax,0x2ebc(%rip)
mov    0x2ec2(%rip),%eax
add    0x2eb4(%rip),%eax
mov    %eax,0x2eae(%rip)
mov    0x2ea4(%rip),%edi
add    0x2ea6(%rip),%edi
mov    0x2e9c(%rip),%esi
call   1040 <get_screen_cache@plt>
movsbl %al,%eax
cmp    $0x20,%eax
je     11be <control_ball+0x9e>
imul   $0xffffffff,0x2e88(%rip),%eax
mov    %eax,0x2e82(%rip)
mov    0x2e74(%rip),%edi
mov    0x2e72(%rip),%esi
add    0x2e74(%rip),%esi
call   1040 <get_screen_cache@plt>
movsbl %al,%eax
cmp    $0x20,%eax
je     11ee <control_ball+0xce>
imul   $0xffffffff,0x2e5c(%rip),%eax
mov    %eax,0x2e56(%rip)
mov    0x2e44(%rip),%edi
mov    0x2e42(%rip),%esi
movsbl 0x2e47(%rip),%edx
call   1030 <set_screen_cache@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<control_ball>:
push   %rax
cmpb   $0x1,0x2f20(%rip)
jne    1144 <control_ball+0x24>
mov    0x2f0c(%rip),%eax
mov    0x2efe(%rip),%edi
mov    0x2efc(%rip),%esi
add    0x2efe(%rip),%esi
jmp    1175 <control_ball+0x55>
movl   $0x1,0x2eee(%rip)
movl   $0xffffffff,0x2ee8(%rip)
ff ff ff
movb   $0x1,0x2ee5(%rip)
movb   $0x1,0x2ee2(%rip)
mov    $0x3,%esi
mov    $0x1,%eax
mov    $0x6,%edi
add    %eax,%edi
mov    %edi,0x2eb7(%rip)
mov    %esi,0x2eb5(%rip)
add    %eax,%edi
call   1040 <get_screen_cache@plt>
cmp    $0x20,%al
je     1194 <control_ball+0x74>
negl   0x2ea8(%rip)
mov    0x2e9a(%rip),%edi
mov    0x2ea0(%rip),%esi
add    0x2e92(%rip),%esi
call   1040 <get_screen_cache@plt>
cmp    $0x20,%al
je     11b5 <control_ball+0x95>
negl   0x2e8b(%rip)
mov    0x2e79(%rip),%edi
xor    %eax,%eax
cmpb   $0x0,0x2e80(%rip)
mov    0x2e6e(%rip),%esi
mov    $0x2a,%edx
cmove  %eax,%edx
pop    %rax
jmp    1030 <set_screen_cache@plt>

LLVM IR (-O0):
%struct.ball_t = type { i32, i32, i32, i32, i8 }
@control_ball.s_ball = internal global %struct.ball_t zeroinitializer
@control_ball.s_first_flag = internal global i32 1
define void @control_ball() {
%1 = load i32, i32* @control_ball.s_first_flag
%2 = icmp eq i32 %1, 1
br i1 %2, label %3, label %4
3: ; preds = %0
store i32 6, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
store i32 4, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
store i32 1, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 2)
store i32 -1, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 3)
store i8 42, i8* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 4)
store i32 0, i32* @control_ball.s_first_flag
br label %4
4: ; preds = %3, %0
%5 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 2)
%6 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
%7 = add nsw i32 %6, %5
store i32 %7, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
%8 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 3)
%9 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
%10 = add nsw i32 %9, %8
store i32 %10, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
%11 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
%12 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 2)
%13 = add nsw i32 %11, %12
%14 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
%15 = call signext i8 @get_screen_cache(i32 %13, i32 %14)
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 32
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 2)
%20 = mul nsw i32 %19, -1
store i32 %20, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 2)
br label %21
21: ; preds = %18, %4
%22 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
%23 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
%24 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 3)
%25 = add nsw i32 %23, %24
%26 = call signext i8 @get_screen_cache(i32 %22, i32 %25)
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 3)
%31 = mul nsw i32 %30, -1
store i32 %31, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 3)
br label %32
32: ; preds = %29, %21
%33 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 0)
%34 = load i32, i32* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 1)
%35 = load i8, i8* getelementptr inbounds (%struct.ball_t, %struct.ball_t* @control_ball.s_ball, i32 0, i32 4)
%36 = call i32 @set_screen_cache(i32 %33, i32 %34, i8 signext %35)
ret void
}

LLVM IR (-O2):
@control_ball.s_ball.0 = internal unnamed_addr global i32 0
@control_ball.s_ball.1 = internal unnamed_addr global i32 0
@control_ball.s_ball.2 = internal unnamed_addr global i32 0
@control_ball.s_ball.3 = internal unnamed_addr global i32 0
@control_ball.s_ball.4 = internal unnamed_addr global i1 false
@control_ball.s_first_flag = internal unnamed_addr global i1 false
define void @control_ball() {
%1 = load i1, i1* @control_ball.s_first_flag
br i1 %1, label %2, label %8
2: ; preds = %0
%3 = load i32, i32* @control_ball.s_ball.2
%4 = load i32, i32* @control_ball.s_ball.0
%5 = load i32, i32* @control_ball.s_ball.3
%6 = load i32, i32* @control_ball.s_ball.1
%7 = add nsw i32 %6, %5
br label %9
8: ; preds = %0
store i32 1, i32* @control_ball.s_ball.2
store i32 -1, i32* @control_ball.s_ball.3
store i1 true, i1* @control_ball.s_ball.4
store i1 true, i1* @control_ball.s_first_flag
br label %9
9: ; preds = %2, %8
%10 = phi i32 [ %4, %2 ], [ 6, %8 ]
%11 = phi i32 [ %3, %2 ], [ 1, %8 ]
%12 = phi i32 [ %7, %2 ], [ 3, %8 ]
%13 = add nsw i32 %10, %11
store i32 %13, i32* @control_ball.s_ball.0
store i32 %12, i32* @control_ball.s_ball.1
%14 = add nsw i32 %13, %11
%15 = tail call signext i8 @get_screen_cache(i32 %14, i32 %12)
%16 = icmp eq i8 %15, 32
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = load i32, i32* @control_ball.s_ball.2
%19 = sub nsw i32 0, %18
store i32 %19, i32* @control_ball.s_ball.2
br label %20
20: ; preds = %17, %9
%21 = load i32, i32* @control_ball.s_ball.0
%22 = load i32, i32* @control_ball.s_ball.1
%23 = load i32, i32* @control_ball.s_ball.3
%24 = add nsw i32 %23, %22
%25 = tail call signext i8 @get_screen_cache(i32 %21, i32 %24)
%26 = icmp eq i8 %25, 32
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = load i32, i32* @control_ball.s_ball.3
%29 = sub nsw i32 0, %28
store i32 %29, i32* @control_ball.s_ball.3
br label %30
30: ; preds = %27, %20
%31 = load i32, i32* @control_ball.s_ball.0
%32 = load i32, i32* @control_ball.s_ball.1
%33 = load i1, i1* @control_ball.s_ball.4
%34 = select i1 %33, i8 42, i8 0
%35 = tail call i32 @set_screen_cache(i32 %31, i32 %32, i8 signext %34)
ret void
}