#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int pack_char_compact(char *);
int /*<<< orphan*/ print_bit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int unpack_char(int, int);
int main(int argc, char *argv[]) {
  int value, byte_position;
  if ((argc < 2) || (strlen(argv[1]) > 4)) {
    fprintf(stderr, "Usage: %s <4 characters>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  printf("%8c%9c%9c%9c\n", argv[1][0], argv[1][1], argv[1][2], argv[1][3]);
  printf("byte%4d byte%4d byte%4d byte%4d\n", 3, 2, 1, 0);
  print_bit(pack_char_compact(argv[1]));
  value = pack_char_compact(argv[1]);
  printf("\n\nGet a byte from the integer value: \'%d\'\n", value);
  printf("Which byte do you want to extract? 0, 1, 2, 3: ");
  scanf("%1d", &byte_position);
  if (byte_position >= 4 || byte_position < 0) {
    fprintf(stderr, "Err. Byte position must be between 0 and 4.\n");
    exit(EXIT_FAILURE);
  }
  printf("The %d byte is: %c\n", byte_position,
         unpack_char(value, byte_position));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11b6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jle    11e2 <main+0x62>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x2(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x3(%rax),%r8d
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe01(%rip),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <pack_char_compact@plt>
mov    %eax,%edi
call   1070 <print_bit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <pack_char_compact@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <scanf@plt>
cmpl   $0x4,-0x18(%rbp)
jge    12a7 <main+0x127>
cmpl   $0x0,-0x18(%rbp)
jge    12cc <main+0x14c>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10a0 <unpack_char@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     1261 <main+0xe1>
mov    0x8(%rbx),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jge    1261 <main+0xe1>
mov    0x8(%rbx),%rax
movsbl (%rax),%esi
movsbl 0x1(%rax),%edx
movsbl 0x2(%rax),%ecx
movsbl 0x3(%rax),%r8d
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
call   1050 <pack_char_compact@plt>
mov    %eax,%edi
call   1070 <print_bit@plt>
mov    0x8(%rbx),%rdi
call   1050 <pack_char_compact@plt>
mov    %eax,%ebx
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe81(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%ebp
cmp    $0x4,%ebp
jae    127d <main+0xfd>
mov    %ebx,%edi
mov    %ebp,%esi
call   10a0 <unpack_char@plt>
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd8c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1294 <main+0x114>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <4 characters>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"%8c%9c%9c%9c\0A\00"
@.str.2 = [33 x i8] c"byte%4d byte%4d byte%4d byte%4d\0A\00"
@.str.3 = [43 x i8] c"\0A\0AGet a byte from the integer value: '%d'\0A\00"
@.str.4 = [48 x i8] c"Which byte do you want to extract? 0, 1, 2, 3: \00"
@.str.5 = [4 x i8] c"%1d\00"
@.str.6 = [45 x i8] c"Err. Byte position must be between 0 and 4.\0A\00"
@.str.7 = [20 x i8] c"The %d byte is: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strlen(i8* %13)
%15 = icmp sgt i32 %14, 4
br i1 %15, label %16, label %24
16: ; preds = %10, %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %36, i32 %42, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 2, i32 1, i32 0)
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @pack_char_compact(i8* %53)
%55 = call i32 @print_bit(i32 %54)
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @pack_char_compact(i8* %58)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%64 = load i32, i32* %7
%65 = icmp sge i32 %64, 4
br i1 %65, label %69, label %66
66: ; preds = %24
%67 = load i32, i32* %7
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %66, %24
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %66
%75 = load i32, i32* %7
%76 = load i32, i32* %6
%77 = load i32, i32* %7
%78 = call i32 @unpack_char(i32 %76, i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %75, i32 %78)
%80 = load i32, i32* @EXIT_SUCCESS
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <4 characters>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"%8c%9c%9c%9c\0A\00"
@.str.2 = [33 x i8] c"byte%4d byte%4d byte%4d byte%4d\0A\00"
@.str.3 = [43 x i8] c"\0A\0AGet a byte from the integer value: '%d'\0A\00"
@.str.4 = [48 x i8] c"Which byte do you want to extract? 0, 1, 2, 3: \00"
@.str.5 = [4 x i8] c"%1d\00"
@.str.6 = [45 x i8] c"Err. Byte position must be between 0 and 4.\0A\00"
@.str.7 = [20 x i8] c"The %d byte is: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 4
br i1 %10, label %11, label %17
11: ; preds = %6, %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds i8, i8* %18, i64 2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = getelementptr inbounds i8, i8* %18, i64 3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23, i32 %26, i32 %29)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 2, i32 1, i32 0)
%32 = load i8*, i8** %7
%33 = tail call i32 @pack_char_compact(i8* %32)
%34 = tail call i32 @print_bit(i32 %33)
%35 = load i8*, i8** %7
%36 = tail call i32 @pack_char_compact(i8* %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%40 = load i32, i32* %3
%41 = icmp ugt i32 %40, 3
br i1 %41, label %42, label %47
42: ; preds = %17
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %17
%48 = call i32 @unpack_char(i32 %36, i32 %40)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %40, i32 %48)
%50 = load i32, i32* @EXIT_SUCCESS
ret i32 %50
}