#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 /*<<< orphan*/ sprintf(char *, char *, int);
int gsb(int adr, int *codes, char *ligne, int n) {
  int a;
  a = codes[2];
  if (n >= 0) {
    a |= (adr & 0xf000) + (n << 10);
    sprintf(ligne, "GSB41C %04X", a);
  } else {
    a |= adr & 0xfc00;
    sprintf(ligne, "GSBSAM %04X", a);
  }
  return (3);
}


x86 assembly (clang, -O0):
<gsb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1168 <gsb+0x58>
mov    -0x4(%rbp),%eax
and    $0xf000,%eax
mov    -0x1c(%rbp),%ecx
shl    $0xa,%ecx
add    %ecx,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xea2(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1189 <gsb+0x79>
mov    -0x4(%rbp),%eax
and    $0xfc00,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe88(%rip),%rsi
call   1030 <sprintf@plt>
mov    $0x3,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsb>:
push   %rax
mov    %rdx,%r8
mov    %edi,%eax
and    $0xfc00,%eax
and    $0xf000,%edi
mov    %ecx,%edx
shl    $0xa,%edx
add    %edi,%edx
test   %ecx,%ecx
cmovs  %eax,%edx
lea    0xecc(%rip),%rax
lea    0xed1(%rip),%rcx
cmovns %rax,%rcx
or     0x8(%rsi),%edx
mov    %r8,%rdi
mov    %rcx,%rsi
call   1030 <sprintf@plt>
mov    $0x3,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"GSB41C %04X\00"
@.str.1 = [12 x i8] c"GSBSAM %04X\00"
define i32 @gsb(i32 %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32*, i32** %6
%11 = getelementptr inbounds i32, i32* %10, i64 2
%12 = load i32, i32* %11
store i32 %12, i32* %9
%13 = load i32, i32* %8
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %4
%16 = load i32, i32* %5
%17 = and i32 %16, 61440
%18 = load i32, i32* %8
%19 = shl i32 %18, 10
%20 = add nsw i32 %17, %19
%21 = load i32, i32* %9
%22 = or i32 %21, %20
store i32 %22, i32* %9
%23 = load i8*, i8** %7
%24 = load i32, i32* %9
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %34
26: ; preds = %4
%27 = load i32, i32* %5
%28 = and i32 %27, 64512
%29 = load i32, i32* %9
%30 = or i32 %29, %28
store i32 %30, i32* %9
%31 = load i8*, i8** %7
%32 = load i32, i32* %9
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %26, %15
ret i32 3
}

LLVM IR (-O2):
@.str = [12 x i8] c"GSB41C %04X\00"
@.str.1 = [12 x i8] c"GSBSAM %04X\00"
define i32 @gsb(i32 %0, i32* nocapture %1, i8* nocapture writeonly %2, i32 %3) {
%5 = getelementptr inbounds i32, i32* %1, i64 2
%6 = load i32, i32* %5
%7 = icmp sgt i32 %3, -1
%8 = and i32 %0, 64512
%9 = and i32 %0, 61440
%10 = shl i32 %3, 10
%11 = add nsw i32 %10, %9
%12 = select i1 %7, i32 %11, i32 %8
%13 = select i1 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%14 = or i32 %6, %12
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %13, i32 %14)
ret i32 3
}