#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 EXIT_SUCCESS;
scalar_t__ dis(void *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ info(char *, ...);
int /*<<< orphan*/ invite(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ titre(char *);
int /*<<< orphan*/ vider_stdin();
int main(void) {
  char *code, result[64];
  unsigned int *memptr, *memstart;
  int i;
  titre("DESASSEMBLEUR MC 68000");
  info("Ce désassembleur est une interface interactive");
  info("pour la fonction \'dis\' qui réalise le désassemblage");
  info("Fonction \'dis\': Copyright (c) 1991 by James Patchell");
  info("Interface : Eric KEDJI <eric_kedji@yahoo.fr>\n");
  memstart = (unsigned int *)malloc(256 * sizeof(unsigned int));
  code = (char *)malloc(1024);
  memptr = memstart;
  invite("Nombre d\'instructions:");
  scanf("%d", &i);
  vider_stdin();
  info("Saisie de la suite de bits à désassembler");
  info("(sans espaces, en hexa, 1024 caractères max)");
  invite("Code:");
  scanf("%1024[^\n]", code);
  (void)getchar();
  for (; i--;) {
    sscanf(code, "%4X", memptr);
    memptr++;
    code += 4;
  }
  info("Code obtenu:\n\n", result);
  memptr = memstart;
  for (i = 5; i > 0; i--) {
    memptr = (unsigned int *)dis((void *)memptr, result);
    info("%s", result);
  }
  printf("\n\n");
  info("Bye!\n\n");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1090 <titre@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xec2(%rip),%rdi
call   1060 <invite@plt>
lea    0xecd(%rip),%rdi
lea    -0x64(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1040 <vider_stdin@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
lea    0xef5(%rip),%rdi
call   1060 <invite@plt>
mov    -0x10(%rbp),%rsi
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x64(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x64(%rbp)
cmp    $0x0,%eax
je     12c2 <main+0x122>
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xec4(%rip),%rsi
call   1080 <sscanf@plt>
mov    -0x58(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    127d <main+0xdd>
lea    -0x50(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x5,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jle    131e <main+0x17e>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <dis@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    12e3 <main+0x143>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   10c0 <info@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe4e(%rip),%rdi
call   1090 <titre@plt>
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xed0(%rip),%rdi
call   1060 <invite@plt>
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
xor    %eax,%eax
call   1040 <vider_stdin@plt>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
lea    0xf02(%rip),%rdi
call   1060 <invite@plt>
lea    0xefc(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
subl   $0x1,0xc(%rsp)
jb     129d <main+0xfd>
lea    0xee7(%rip),%r15
mov    %r14,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <sscanf@plt>
add    $0x4,%rbx
add    $0x4,%r12
subl   $0x1,0xc(%rsp)
jae    1280 <main+0xe0>
lea    0xec4(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <info@plt>
movl   $0x5,0xc(%rsp)
lea    0xeb5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <dis@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <info@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x1,%eax
jg     12d0 <main+0x130>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   10c0 <info@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"DESASSEMBLEUR MC 68000\00"
@.str.1 = [48 x i8] c"Ce d\C3\A9sassembleur est une interface interactive\00"
@.str.2 = [54 x i8] c"pour la fonction 'dis' qui r\C3\A9alise le d\C3\A9sassemblage\00"
@.str.3 = [53 x i8] c"Fonction 'dis': Copyright (c) 1991 by James Patchell\00"
@.str.4 = [46 x i8] c"Interface : Eric KEDJI <eric_kedji@yahoo.fr>\0A\00"
@.str.5 = [23 x i8] c"Nombre d'instructions:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [44 x i8] c"Saisie de la suite de bits \C3\A0 d\C3\A9sassembler\00"
@.str.8 = [46 x i8] c"(sans espaces, en hexa, 1024 caract\C3\A8res max)\00"
@.str.9 = [6 x i8] c"Code:\00"
@.str.10 = [10 x i8] c"%1024[^\0A]\00"
@.str.11 = [4 x i8] c"%4X\00"
@.str.12 = [15 x i8] c"Code obtenu:\0A\0A\00"
@.str.13 = [3 x i8] c"%s\00"
@.str.14 = [3 x i8] c"\0A\0A\00"
@.str.15 = [7 x i8] c"Bye!\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [64 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @titre(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%12 = call i64 @malloc(i32 1024)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %5
%14 = call i64 @malloc(i32 1024)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %2
%16 = load i32*, i32** %5
store i32* %16, i32** %4
%17 = call i32 @invite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %6)
%19 = call i32 (...) @vider_stdin()
%20 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
%22 = call i32 @invite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%23 = load i8*, i8** %2
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %23)
%25 = call i32 (...) @getchar()
br label %26
26: ; preds = %30, %0
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
%29 = icmp ne i32 %27, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i8*, i8** %2
%32 = load i32*, i32** %4
%33 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32* %32)
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %4
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 4
store i8* %37, i8** %2
br label %26
38: ; preds = %26
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%40 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %5
store i32* %41, i32** %4
store i32 5, i32* %6
br label %42
42: ; preds = %53, %38
%43 = load i32, i32* %6
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32*, i32** %4
%47 = bitcast i32* %46 to i8*
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%49 = call i64 @dis(i8* %47, i8* %48)
%50 = inttoptr i64 %49 to i32*
store i32* %50, i32** %4
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%52 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %6
%55 = add nsw i32 %54, -1
store i32 %55, i32* %6
br label %42
56: ; preds = %42
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%58 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@.str = [23 x i8] c"DESASSEMBLEUR MC 68000\00"
@.str.1 = [48 x i8] c"Ce d\C3\A9sassembleur est une interface interactive\00"
@.str.2 = [54 x i8] c"pour la fonction 'dis' qui r\C3\A9alise le d\C3\A9sassemblage\00"
@.str.3 = [53 x i8] c"Fonction 'dis': Copyright (c) 1991 by James Patchell\00"
@.str.4 = [46 x i8] c"Interface : Eric KEDJI <eric_kedji@yahoo.fr>\0A\00"
@.str.5 = [23 x i8] c"Nombre d'instructions:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [44 x i8] c"Saisie de la suite de bits \C3\A0 d\C3\A9sassembler\00"
@.str.8 = [46 x i8] c"(sans espaces, en hexa, 1024 caract\C3\A8res max)\00"
@.str.9 = [6 x i8] c"Code:\00"
@.str.10 = [10 x i8] c"%1024[^\0A]\00"
@.str.11 = [4 x i8] c"%4X\00"
@.str.12 = [15 x i8] c"Code obtenu:\0A\0A\00"
@.str.13 = [3 x i8] c"%s\00"
@.str.15 = [7 x i8] c"Bye!\0A\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @titre(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i32*
%12 = tail call i64 @malloc(i32 1024)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @invite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%16 = call i32 (...) @vider_stdin()
%17 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%18 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
%19 = call i32 @invite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %13)
%21 = call i32 (...) @getchar()
%22 = load i32, i32* %2
%23 = add nsw i32 %22, -1
store i32 %23, i32* %2
%24 = icmp eq i32 %22, 0
br i1 %24, label %34, label %25
25: ; preds = %0, %25
%26 = phi i8* [ %30, %25 ], [ %13, %0 ]
%27 = phi i32* [ %29, %25 ], [ %11, %0 ]
%28 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32* %27)
%29 = getelementptr inbounds i32, i32* %27, i64 1
%30 = getelementptr inbounds i8, i8* %26, i64 4
%31 = load i32, i32* %2
%32 = add nsw i32 %31, -1
store i32 %32, i32* %2
%33 = icmp eq i32 %31, 0
br i1 %33, label %34, label %25
34: ; preds = %25, %0
%35 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %3)
store i32 5, i32* %2
br label %36
36: ; preds = %34, %36
%37 = phi i32* [ %11, %34 ], [ %40, %36 ]
%38 = bitcast i32* %37 to i8*
%39 = call i64 @dis(i8* %38, i8* %3)
%40 = inttoptr i64 %39 to i32*
%41 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %3)
%42 = load i32, i32* %2
%43 = add nsw i32 %42, -1
store i32 %43, i32* %2
%44 = icmp sgt i32 %42, 1
br i1 %44, label %36, label %45
45: ; preds = %36
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%47 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}