#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 fail_real(int /*<<< orphan*/, int);
int sext_i16to32(int);
long long sext_i32to64(int);
int sext_i8to16(int);
int test_sext(void) {
  if (sext_i8to16(-4) != -4)
    return fail_real(0, 571);
  if (sext_i16to32(-6) != -6)
    return fail_real(0, 573);
  if (sext_i32to64(-6) != -6ll)
    return fail_real(0, 575);
  return 0x1000000;
}


x86 assembly (clang, -O0):
<test_sext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xfffffffc,%edi
call   1040 <sext_i8to16@plt>
cmp    $0xfffffffc,%eax
je     116f <test_sext+0x2f>
xor    %edi,%edi
mov    $0x23b,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11c5 <test_sext+0x85>
mov    $0xfffffffa,%edi
call   1060 <sext_i16to32@plt>
cmp    $0xfffffffa,%eax
je     1196 <test_sext+0x56>
xor    %edi,%edi
mov    $0x23d,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11c5 <test_sext+0x85>
mov    $0xfffffffa,%edi
call   1050 <sext_i32to64@plt>
cmp    $0xfffffffffffffffa,%rax
je     11be <test_sext+0x7e>
xor    %edi,%edi
mov    $0x23f,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11c5 <test_sext+0x85>
movl   $0x1000000,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sext>:
push   %rax
mov    $0xfffffffc,%edi
call   1040 <sext_i8to16@plt>
mov    $0x23b,%esi
cmp    $0xfffffffc,%eax
jne    1185 <test_sext+0x45>
mov    $0xfffffffa,%edi
call   1060 <sext_i16to32@plt>
mov    $0x23d,%esi
cmp    $0xfffffffa,%eax
jne    1185 <test_sext+0x45>
mov    $0xfffffffa,%edi
call   1050 <sext_i32to64@plt>
mov    $0x23f,%esi
cmp    $0xfffffffffffffffa,%rax
jne    1185 <test_sext+0x45>
mov    $0x1000000,%eax
pop    %rcx
ret
xor    %edi,%edi
pop    %rax
jmp    1030 <fail_real@plt>

LLVM IR (-O0):
define i32 @test_sext() {
%1 = alloca i32
%2 = call i32 @sext_i8to16(i32 -4)
%3 = icmp ne i32 %2, -4
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @fail_real(i32 0, i32 571)
store i32 %5, i32* %1
br label %17
6: ; preds = %0
%7 = call i32 @sext_i16to32(i32 -6)
%8 = icmp ne i32 %7, -6
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @fail_real(i32 0, i32 573)
store i32 %10, i32* %1
br label %17
11: ; preds = %6
%12 = call i64 @sext_i32to64(i32 -6)
%13 = icmp ne i64 %12, -6
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @fail_real(i32 0, i32 575)
store i32 %15, i32* %1
br label %17
16: ; preds = %11
store i32 16777216, i32* %1
br label %17
17: ; preds = %16, %14, %9, %4
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
define i32 @test_sext() {
%1 = tail call i32 @sext_i8to16(i32 -4)
%2 = icmp eq i32 %1, -4
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = tail call i32 @sext_i16to32(i32 -6)
%5 = icmp eq i32 %4, -6
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i64 @sext_i32to64(i32 -6)
%8 = icmp eq i64 %7, -6
br i1 %8, label %12, label %9
9: ; preds = %6, %3, %0
%10 = phi i32 [ 571, %0 ], [ 573, %3 ], [ 575, %6 ]
%11 = tail call i32 @fail_real(i32 0, i32 %10)
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ 16777216, %6 ], [ %11, %9 ]
ret i32 %13
}