#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 leftShift(int, int);
int twoToThePowerOf(int);
int encodeIFormat(int opcode, int rs, int rt, int immediate) {
  if (immediate < 0)
    immediate = immediate + twoToThePowerOf(16);
  return leftShift(leftShift(leftShift(opcode, 5) + rs, 5) + rt, 16) +
         immediate;
}


x86 assembly (clang, -O0):
<encodeIFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1158 <encodeIFormat+0x38>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x10,%edi
call   1030 <twoToThePowerOf@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
call   1040 <leftShift@plt>
mov    %eax,%edi
add    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1040 <leftShift@plt>
mov    %eax,%edi
add    -0xc(%rbp),%edi
mov    $0x10,%esi
call   1040 <leftShift@plt>
add    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeIFormat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r15d
test   %ecx,%ecx
jns    1142 <encodeIFormat+0x22>
mov    $0x10,%edi
call   1030 <twoToThePowerOf@plt>
add    %eax,%r14d
mov    %r15d,%edi
mov    $0x5,%esi
call   1040 <leftShift@plt>
add    %eax,%ebx
mov    %ebx,%edi
mov    $0x5,%esi
call   1040 <leftShift@plt>
add    %eax,%ebp
mov    %ebp,%edi
mov    $0x10,%esi
call   1040 <leftShift@plt>
add    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @encodeIFormat(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32, i32* %8
%13 = call i32 @twoToThePowerOf(i32 16)
%14 = add nsw i32 %12, %13
store i32 %14, i32* %8
br label %15
15: ; preds = %11, %4
%16 = load i32, i32* %5
%17 = call i32 @leftShift(i32 %16, i32 5)
%18 = load i32, i32* %6
%19 = add nsw i32 %17, %18
%20 = call i32 @leftShift(i32 %19, i32 5)
%21 = load i32, i32* %7
%22 = add nsw i32 %20, %21
%23 = call i32 @leftShift(i32 %22, i32 16)
%24 = load i32, i32* %8
%25 = add nsw i32 %23, %24
ret i32 %25
}

LLVM IR (-O2):
define i32 @encodeIFormat(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = tail call i32 @twoToThePowerOf(i32 16)
%8 = add nsw i32 %7, %3
br label %9
9: ; preds = %6, %4
%10 = phi i32 [ %8, %6 ], [ %3, %4 ]
%11 = tail call i32 @leftShift(i32 %0, i32 5)
%12 = add nsw i32 %11, %1
%13 = tail call i32 @leftShift(i32 %12, i32 5)
%14 = add nsw i32 %13, %2
%15 = tail call i32 @leftShift(i32 %14, i32 16)
%16 = add nsw i32 %15, %10
ret i32 %16
}