#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int getByte(char *);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, i, n;
  char buffer[1000];
  char tempFile[20];
  char str[300];
  while (1) {
    strcpy(tempFile, "tmp_XXXXXX");
    if ((fd = mkstemp(tempFile)) == -1) {
      perror("temp file create failed!\n");
      exit(1);
    }
    printf("> ");
    fgets(buffer, 1000, stdin);
    for (i = 0; i < strlen(buffer) - 1; i += 2) {
      n = getByte(buffer + i);
      if (n == -1) {
        printf("unknown character!\n");
        goto next;
      }
      write(fd, (char *)&n, 1);
    }
  next:
    sprintf(str, "mipsel-linux-objdump -D -m mips -b binary %s | sed \'1, 7d\'",
            tempFile);
    system(str);
    close(fd);
    unlink(tempFile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x570,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x430(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x430(%rbp),%rdi
call   10c0 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    122a <main+0x5a>
lea    0xdf0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xdf4(%rip),%rdi
call   1090 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   10b0 <fgets@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x564(%rbp)
lea    -0x410(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x564(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12cf <main+0xff>
lea    -0x410(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1060 <getByte@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b0 <main+0xe0>
lea    0xd82(%rip),%rdi
call   1090 <printf@plt>
jmp    12d4 <main+0x104>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1257 <main+0x87>
jmp    12d4 <main+0x104>
lea    -0x560(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xd53(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x560(%rbp),%rdi
call   1080 <system@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
jmp    11e9 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x548,%rsp
lea    0xe08(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   10d0 <mkstemp@plt>
cmp    $0xffffffff,%eax
jne    1228 <main+0x48>
lea    0xdf2(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%r13d
lea    0x160(%rsp),%rbx
lea    0xc(%rsp),%r12
lea    0x30(%rsp),%rbp
lea    0x10(%rsp),%r15
jmp    12a9 <main+0xc9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe0c(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
lea    0xdc2(%rip),%rsi
mov    %r15,%rdx
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1090 <system@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %r15,%rdi
lea    0xd70(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   10d0 <mkstemp@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1212 <main+0x32>
lea    0xd75(%rip),%rdi
call   10a0 <printf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cmp    $0x2,%eax
jl     125c <main+0x7c>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%r14,1),%rdi
add    $0x160,%rdi
call   1070 <getByte@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1250 <main+0x70>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <write@plt>
add    $0x2,%r14
mov    %rbx,%rdi
call   1080 <strlen@plt>
add    $0xffffffff,%eax
cmp    %r14d,%eax
jg     12e0 <main+0x100>
jmp    125c <main+0x7c>

LLVM IR (-O0):
@.str = [11 x i8] c"tmp_XXXXXX\00"
@.str.1 = [26 x i8] c"temp file create failed!\0A\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.3 = [20 x i8] c"unknown character!\0A\00"
@.str.4 = [59 x i8] c"mipsel-linux-objdump -D -m mips -b binary %s | sed '1, 7d'\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1000 x i8]
%10 = alloca [20 x i8]
%11 = alloca [300 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %12
12: ; preds = %2, %50
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%16 = call i32 @mkstemp(i8* %15)
store i32 %16, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%24 = load i32, i32* @stdin
%25 = call i32 @fgets(i8* %23, i32 1000, i32 %24)
store i32 0, i32* %7
br label %26
26: ; preds = %46, %21
%27 = load i32, i32* %7
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = icmp slt i32 %27, %30
br i1 %31, label %32, label %49
32: ; preds = %26
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = call i32 @getByte(i8* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %50
42: ; preds = %32
%43 = load i32, i32* %6
%44 = bitcast i32* %8 to i8*
%45 = call i32 @write(i32 %43, i8* %44, i32 1)
br label %46
46: ; preds = %42
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 2
store i32 %48, i32* %7
br label %26
49: ; preds = %26
br label %50
50: ; preds = %49, %40
%51 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%55 = call i32 @system(i8* %54)
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%59 = call i32 @unlink(i8* %58)
br label %12
}

LLVM IR (-O2):
@.str = [11 x i8] c"tmp_XXXXXX\00"
@.str.1 = [26 x i8] c"temp file create failed!\0A\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.4 = [59 x i8] c"mipsel-linux-objdump -D -m mips -b binary %s | sed '1, 7d'\00"
@str = [19 x i8] c"unknown character!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [20 x i8]
%6 = alloca [300 x i8]
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%11 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @mkstemp(i8* %9)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %38, %2
%15 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2, %38
%18 = phi i32 [ %44, %38 ], [ %12, %2 ]
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %8, i32 1000, i32 %20)
%22 = call i32 @strlen(i8* %8)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %38
24: ; preds = %17, %31
%25 = phi i64 [ %33, %31 ], [ 0, %17 ]
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %25
%27 = call i32 @getByte(i8* %26)
store i32 %27, i32* %3
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %38
31: ; preds = %24
%32 = call i32 @write(i32 %18, i8* %7, i32 1)
%33 = add nuw i64 %25, 2
%34 = call i32 @strlen(i8* %8)
%35 = add nsw i32 %34, -1
%36 = trunc i64 %33 to i32
%37 = icmp sgt i32 %35, %36
br i1 %37, label %24, label %38
38: ; preds = %31, %17, %29
%39 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%40 = call i32 @system(i8* %10)
%41 = call i32 @close(i32 %18)
%42 = call i32 @unlink(i8* %9)
%43 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @mkstemp(i8* %9)
%45 = icmp eq i32 %44, -1
br i1 %45, label %14, label %17
}