#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*/ printf(char *, char, char);
int main() {
  short int i;
  signed char ch;
  for (i = 0x80; i != 0; i = (i >> 1)) {
    printf("i is %x (%d)\n", i, i);
  }
  for (ch = 0x80; ch != 0; ch = (ch >> 1)) {
    printf("ch is %x (%d)\n", ch, ch);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x80,-0x6(%rbp)
movswl -0x6(%rbp),%eax
cmp    $0x0,%eax
je     115e <main+0x4e>
mov    -0x6(%rbp),%ax
mov    %al,%cl
mov    -0x6(%rbp),%ax
lea    0xebd(%rip),%rdi
movsbl %cl,%esi
movsbl %al,%edx
call   1030 <printf@plt>
movswl -0x6(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0x6(%rbp)
jmp    1125 <main+0x15>
movb   $0x80,-0x7(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x0,%eax
je     1194 <main+0x84>
mov    -0x7(%rbp),%al
lea    0xe95(%rip),%rdi
movsbl %al,%esi
movsbl -0x7(%rbp),%edx
call   1030 <printf@plt>
movsbl -0x7(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x7(%rbp)
jmp    1162 <main+0x52>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xee5(%rip),%rbx
mov    %rbx,%rdi
mov    $0xffffff80,%esi
mov    $0xffffff80,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0x40,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    $0x10,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x8,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <printf@plt>
mov    $0x80,%bl
lea    0xe5a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %bl,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
sar    %bl
jmp    11c0 <main+0xb0>

LLVM IR (-O0):
@.str = [14 x i8] c"i is %x (%d)\0A\00"
@.str.1 = [15 x i8] c"ch is %x (%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8
store i32 0, i32* %1
store i16 128, i16* %2
br label %4
4: ; preds = %14, %0
%5 = load i16, i16* %2
%6 = sext i16 %5 to i32
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = load i16, i16* %2
%10 = trunc i16 %9 to i8
%11 = load i16, i16* %2
%12 = trunc i16 %11 to i8
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext %10, i8 signext %12)
br label %14
14: ; preds = %8
%15 = load i16, i16* %2
%16 = sext i16 %15 to i32
%17 = ashr i32 %16, 1
%18 = trunc i32 %17 to i16
store i16 %18, i16* %2
br label %4
19: ; preds = %4
store i8 -128, i8* %3
br label %20
20: ; preds = %28, %19
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i8, i8* %3
%26 = load i8, i8* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %25, i8 signext %26)
br label %28
28: ; preds = %24
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = ashr i32 %30, 1
%32 = trunc i32 %31 to i8
store i8 %32, i8* %3
br label %20
33: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"i is %x (%d)\0A\00"
@.str.1 = [15 x i8] c"ch is %x (%d)\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext -128, i8 signext -128)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 64, i8 signext 64)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 32, i8 signext 32)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 16, i8 signext 16)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 8, i8 signext 8)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 4, i8 signext 4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 2, i8 signext 2)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 1, i8 signext 1)
br label %9
9: ; preds = %0, %9
%10 = phi i8 [ %12, %9 ], [ -128, %0 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %10, i8 signext %10)
%12 = ashr i8 %10, 1
br label %9
}