char *manageplayer_1_svc(char *arg, struct svc_req *req) {
  static char player_a = '0';
  static char player_b = '0';
  static char res;
  if (*arg == '0') {
    if (player_a == '0') {
      player_a = '1';
      res = '1';
      return &res;
    }
    if (player_b == '0') {
      player_b = '1';
      res = '2';
      return &res;
    }
    res = '0';
    return &res;
  } else {
    if (*arg == '1') {
      player_a = '0';
      res = '3';
      return &res;
    }
    if (*arg == '2') {
      player_b = '0';
      res = '4';
      return &res;
    }
  }
  res = '0';
  return &res;
}


x86 assembly (clang, -O0):
<manageplayer_1_svc>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    118f <manageplayer_1_svc+0x8f>
movsbl 0x2efd(%rip),%eax
cmp    $0x30,%eax
jne    114a <manageplayer_1_svc+0x4a>
movb   $0x31,0x2eed(%rip)
movb   $0x31,0x2ee9(%rip)
lea    0x2ee2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <manageplayer_1_svc+0x102>
movsbl 0x2ed0(%rip),%eax
cmp    $0x30,%eax
jne    1178 <manageplayer_1_svc+0x78>
movb   $0x31,0x2ec0(%rip)
movb   $0x32,0x2ebb(%rip)
lea    0x2eb4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <manageplayer_1_svc+0x102>
movb   $0x30,0x2ea4(%rip)
lea    0x2e9d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <manageplayer_1_svc+0x102>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    11bd <manageplayer_1_svc+0xbd>
movb   $0x30,0x2e7a(%rip)
movb   $0x33,0x2e76(%rip)
lea    0x2e6f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <manageplayer_1_svc+0x102>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x32,%eax
jne    11eb <manageplayer_1_svc+0xeb>
movb   $0x30,0x2e4d(%rip)
movb   $0x34,0x2e48(%rip)
lea    0x2e41(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <manageplayer_1_svc+0x102>
jmp    11f0 <manageplayer_1_svc+0xf0>
movb   $0x30,0x2e2c(%rip)
lea    0x2e25(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<manageplayer_1_svc>:
mov    (%rdi),%cl
cmp    $0x32,%cl
je     1130 <manageplayer_1_svc+0x30>
cmp    $0x31,%cl
je     113b <manageplayer_1_svc+0x3b>
mov    $0x30,%al
cmp    $0x30,%cl
jne    114f <manageplayer_1_svc+0x4f>
cmpb   $0x0,0x2f07(%rip)
je     1146 <manageplayer_1_svc+0x46>
cmpb   $0x0,0x2eff(%rip)
jne    114f <manageplayer_1_svc+0x4f>
movb   $0x1,0x2ef6(%rip)
mov    $0x32,%al
jmp    114f <manageplayer_1_svc+0x4f>
movb   $0x0,0x2eeb(%rip)
mov    $0x34,%al
jmp    114f <manageplayer_1_svc+0x4f>
movb   $0x0,0x2edf(%rip)
mov    $0x33,%al
jmp    114f <manageplayer_1_svc+0x4f>
movb   $0x1,0x2ed4(%rip)
mov    $0x31,%al
mov    %al,0x2ece(%rip)
lea    0x2ec7(%rip),%rax
ret

LLVM IR (-O0):
%struct.svc_req = type opaque
@manageplayer_1_svc.player_a = internal global i8 48
@manageplayer_1_svc.player_b = internal global i8 48
@manageplayer_1_svc.res = internal global i8 0
define i8* @manageplayer_1_svc(i8* %0, %struct.svc_req* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.svc_req*
store i8* %0, i8** %4
store %struct.svc_req* %1, %struct.svc_req** %5
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 48
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i8, i8* @manageplayer_1_svc.player_a
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 48
br i1 %13, label %14, label %15
14: ; preds = %10
store i8 49, i8* @manageplayer_1_svc.player_a
store i8 49, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
15: ; preds = %10
%16 = load i8, i8* @manageplayer_1_svc.player_b
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 48
br i1 %18, label %19, label %20
19: ; preds = %15
store i8 49, i8* @manageplayer_1_svc.player_b
store i8 50, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
20: ; preds = %15
store i8 48, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 49
br i1 %25, label %26, label %27
26: ; preds = %21
store i8 48, i8* @manageplayer_1_svc.player_a
store i8 51, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 50
br i1 %31, label %32, label %33
32: ; preds = %27
store i8 48, i8* @manageplayer_1_svc.player_b
store i8 52, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
33: ; preds = %27
br label %34
34: ; preds = %33
store i8 48, i8* @manageplayer_1_svc.res
store i8* @manageplayer_1_svc.res, i8** %3
br label %35
35: ; preds = %34, %32, %26, %20, %19, %14
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
%struct.svc_req = type opaque
@manageplayer_1_svc.player_a = internal unnamed_addr global i1 false
@manageplayer_1_svc.player_b = internal unnamed_addr global i1 false
@manageplayer_1_svc.res = internal global i8 0
define i8* @manageplayer_1_svc(i8* nocapture %0, %struct.svc_req* nocapture readnone %1) {
%3 = load i8, i8* %0
switch i8 %3, label %12 [
i8 48, label %4
i8 49, label %10
i8 50, label %11
]
4: ; preds = %2
%5 = load i1, i1* @manageplayer_1_svc.player_a
br i1 %5, label %7, label %6
6: ; preds = %4
store i1 true, i1* @manageplayer_1_svc.player_a
br label %12
7: ; preds = %4
%8 = load i1, i1* @manageplayer_1_svc.player_b
br i1 %8, label %12, label %9
9: ; preds = %7
store i1 true, i1* @manageplayer_1_svc.player_b
br label %12
10: ; preds = %2
store i1 false, i1* @manageplayer_1_svc.player_a
br label %12
11: ; preds = %2
store i1 false, i1* @manageplayer_1_svc.player_b
br label %12
12: ; preds = %2, %7, %11, %10, %9, %6
%13 = phi i8 [ 52, %11 ], [ 51, %10 ], [ 50, %9 ], [ 49, %6 ], [ 48, %7 ], [ 48, %2 ]
store i8 %13, i8* @manageplayer_1_svc.res
ret i8* @manageplayer_1_svc.res
}