#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 satsys(int, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int sat2code(int sat, char *code) {
  int prn;
  switch (satsys(sat, &prn)) {
  case 0x01:
    sprintf(code, "G%2d", prn - 1 + 1);
    break;
  case 0x04:
    sprintf(code, "R%2d", prn - 0 + 1);
    break;
  case 0x08:
    sprintf(code, "E%2d", prn - 0 + 1);
    break;
  case 0x02:
    sprintf(code, "S%2d", prn - 100);
    break;
  case 0x10:
    sprintf(code, "J%2d", prn - 0 + 1);
    break;
  case 0x20:
    sprintf(code, "C%2d", prn - 0 + 1);
    break;
  default:
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<sat2code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1030 <satsys@plt>
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x1f,%eax
ja     1212 <sat2code+0xf2>
mov    -0x20(%rbp),%rax
lea    0xea8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
add    $0x1,%edx
lea    0xf0b(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x0,%edx
add    $0x1,%edx
lea    0xef2(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x0,%edx
add    $0x1,%edx
lea    0xed9(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x64,%edx
lea    0xec3(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x0,%edx
add    $0x1,%edx
lea    0xeaa(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x0,%edx
add    $0x1,%edx
lea    0xe91(%rip),%rsi
call   1040 <sprintf@plt>
jmp    121e <sat2code+0xfe>
movl   $0x0,-0x4(%rbp)
jmp    1225 <sat2code+0x105>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sat2code>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rsi
call   1030 <satsys@plt>
mov    %eax,%ecx
xor    %eax,%eax
add    $0xffffffff,%ecx
cmp    $0x1f,%ecx
ja     11b6 <sat2code+0x96>
lea    0xebb(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    0xc(%rsp),%edx
lea    0xf27(%rip),%rsi
jmp    11a9 <sat2code+0x89>
mov    0xc(%rsp),%edx
add    $0xffffff9c,%edx
lea    0xf26(%rip),%rsi
jmp    11a9 <sat2code+0x89>
mov    0xc(%rsp),%edx
add    $0x1,%edx
lea    0xf0c(%rip),%rsi
jmp    11a9 <sat2code+0x89>
mov    0xc(%rsp),%edx
add    $0x1,%edx
lea    0xf01(%rip),%rsi
jmp    11a9 <sat2code+0x89>
mov    0xc(%rsp),%edx
add    $0x1,%edx
lea    0xefb(%rip),%rsi
jmp    11a9 <sat2code+0x89>
mov    0xc(%rsp),%edx
add    $0x1,%edx
lea    0xef0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"G%2d\00"
@.str.1 = [5 x i8] c"R%2d\00"
@.str.2 = [5 x i8] c"E%2d\00"
@.str.3 = [5 x i8] c"S%2d\00"
@.str.4 = [5 x i8] c"J%2d\00"
@.str.5 = [5 x i8] c"C%2d\00"
define i32 @sat2code(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = call i32 @satsys(i32 %7, i32* %6)
switch i32 %8, label %44 [
i32 1, label %9
i32 4, label %15
i32 8, label %21
i32 2, label %27
i32 16, label %32
i32 32, label %38
]
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = add nsw i32 %12, 1
%14 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %45
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 0
%19 = add nsw i32 %18, 1
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %45
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 0
%25 = add nsw i32 %24, 1
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %45
27: ; preds = %2
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 100
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %45
32: ; preds = %2
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 0
%36 = add nsw i32 %35, 1
%37 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %45
38: ; preds = %2
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 0
%42 = add nsw i32 %41, 1
%43 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %45
44: ; preds = %2
store i32 0, i32* %3
br label %46
45: ; preds = %38, %32, %27, %21, %15, %9
store i32 1, i32* %3
br label %46
46: ; preds = %45, %44
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c"G%2d\00"
@.str.1 = [5 x i8] c"R%2d\00"
@.str.2 = [5 x i8] c"E%2d\00"
@.str.3 = [5 x i8] c"S%2d\00"
@.str.4 = [5 x i8] c"J%2d\00"
@.str.5 = [5 x i8] c"C%2d\00"
define i32 @sat2code(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @satsys(i32 %0, i32* %3)
switch i32 %5, label %29 [
i32 1, label %6
i32 4, label %9
i32 8, label %13
i32 2, label %17
i32 16, label %21
i32 32, label %25
]
6: ; preds = %2
%7 = load i32, i32* %3
%8 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %29
9: ; preds = %2
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %29
13: ; preds = %2
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
%16 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %29
17: ; preds = %2
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -100
%20 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %29
21: ; preds = %2
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %29
25: ; preds = %2
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %6, %9, %13, %17, %21, %25, %2
%30 = phi i32 [ 0, %2 ], [ 1, %25 ], [ 1, %21 ], [ 1, %17 ], [ 1, %13 ], [ 1, %9 ], [ 1, %6 ]
ret i32 %30
}