#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*/ atoi(char *);
int /*<<< orphan*/ close(int);
int get_modem_memory(int, char *, int /*<<< orphan*/);
int init_modem(int);
int init_port(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("usage: %s PAGE DUMPFILE\n", argv[0]);
    printf("\tPAGE\t\t -1 for all memory dump, 0-63 for single page dump\n");
    printf("\tDUMPFILE\tfile where write memory dump\n");
    return 1;
  }
  int fd = init_port("/dev/ttyS0");
  int res = 0;
  res = init_modem(fd);
  if (res != 0)
    return res;
  res = get_modem_memory(fd, argv[2], atoi(argv[1]));
  if (res != 0)
    return res;
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bd <main+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <main+0xe7>
lea    0xeb8(%rip),%rdi
call   1060 <init_port@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <init_modem@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f3 <main+0x93>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <main+0xe7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <get_modem_memory@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1238 <main+0xd8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <main+0xe7>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11ab <main+0x3b>
mov    (%rbx),%rsi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11ea <main+0x7a>
lea    0xe67(%rip),%rdi
call   1070 <init_port@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1090 <init_modem@plt>
test   %eax,%eax
jne    11ea <main+0x7a>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rbx
call   1080 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <get_modem_memory@plt>
test   %eax,%eax
jne    11ea <main+0x7a>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"usage: %s PAGE DUMPFILE\0A\00"
@.str.1 = [59 x i8] c"\09PAGE\09\09 -1 for all memory dump, 0-63 for single page dump\0A\00"
@.str.2 = [40 x i8] c"\09DUMPFILE\09file where write memory dump\0A\00"
@.str.3 = [11 x i8] c"/dev/ttyS0\00"
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, 3
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %42
17: ; preds = %2
%18 = call i32 @init_port(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 %18, i32* %6
store i32 0, i32* %7
%19 = load i32, i32* %6
%20 = call i32 @init_modem(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* %7
store i32 %24, i32* %3
br label %42
25: ; preds = %17
%26 = load i32, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
%34 = call i32 @get_modem_memory(i32 %26, i8* %29, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = load i32, i32* %7
store i32 %38, i32* %3
br label %42
39: ; preds = %25
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %37, %23, %10
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [25 x i8] c"usage: %s PAGE DUMPFILE\0A\00"
@.str.3 = [11 x i8] c"/dev/ttyS0\00"
@str = [58 x i8] c"\09PAGE\09\09 -1 for all memory dump, 0-63 for single page dump\00"
@str.4 = [39 x i8] c"\09DUMPFILE\09file where write memory dump\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.4, i64 0, i64 0))
br label %23
9: ; preds = %2
%10 = tail call i32 @init_port(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @init_modem(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 @get_modem_memory(i32 %10, i8* %15, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = tail call i32 @close(i32 %10)
br label %23
23: ; preds = %21, %9, %13, %4
%24 = phi i32 [ 1, %4 ], [ 0, %21 ], [ %11, %9 ], [ %19, %13 ]
ret i32 %24
}