#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*/ assert(int);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
char read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char write(int, char *, int);
int write_cmd(int, char *);
int get_modem_memory(int fd, char *fileName, char pageNum) {
  char *terminator = "\r\nOK\r\n";
  int pos_term = 0;
  int output;
  char cmd[11];
  char n, ch;
  if (pageNum == -1)
    strncpy(cmd, "at+mtm\r\0", 11);
  else if (pageNum > 63)
    return 1;
  else {
    char num[3] = "\0\0\0";
    if (pageNum < 10)
      num[0] = '0' + pageNum;
    else {
      num[1] = '0' + (pageNum % 10);
      num[0] = '0' + (pageNum / 10);
    }
    strncpy(cmd, "at+mtp=\0", 11);
    strcat(cmd, num);
    strcat(cmd, "\r\0");
  }
  printf("get_modem_memory: command to send: %s\n", cmd);
  fflush(stdout);
  int errId = write_cmd(fd, cmd);
  if (errId < 0) {
    fprintf(stderr, "write_cmd error %d\n", errId);
    return 2;
  }
  output = creat(fileName, 00644);
  do {
    n = read(fd, &ch, 1);
    assert(n != 0);
    if (ch == terminator[pos_term])
      pos_term++;
    else if (ch == terminator[0]) {
      n = write(output, terminator, pos_term);
      if (n != pos_term) {
        fprintf(stderr, "error during the write of dumpfile\n");
        close(output);
        return 3;
      }
      pos_term = 1;
    } else {
      if (pos_term > 0) {
        n = write(output, terminator, pos_term);
        if (n != pos_term) {
          fprintf(stderr, "error during the write of dumpfile\n");
          close(output);
          return 4;
        }
        pos_term = 0;
      }
      n = write(output, &ch, 1);
      if (n != 1) {
        fprintf(stderr, "error during the write of dumpfile\n");
        close(output);
        return 4;
      }
    }
  } while (pos_term < 6);
  n = read(fd, &ch, 1);
  assert(n == 0);
  close(output);
  return 0;
}


x86 assembly (clang, -O0):
<get_modem_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
lea    0xe25(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0xffffffff,%eax
jne    120d <get_modem_memory+0x4d>
lea    -0x33(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
jmp    12af <get_modem_memory+0xef>
movsbl -0x11(%rbp),%eax
cmp    $0x3f,%eax
jle    1226 <get_modem_memory+0x66>
movl   $0x1,-0x4(%rbp)
jmp    14cb <get_modem_memory+0x30b>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1060 <memset@plt>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jge    1252 <get_modem_memory+0x92>
movsbl -0x11(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x38(%rbp)
jmp    1278 <get_modem_memory+0xb8>
movsbl -0x11(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x37(%rbp)
movsbl -0x11(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x38(%rbp)
lea    -0x33(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
lea    -0x33(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10d0 <strcat@plt>
lea    -0x33(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   10d0 <strcat@plt>
jmp    12af <get_modem_memory+0xef>
lea    -0x33(%rbp),%rsi
lea    0xd4d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    -0x8(%rbp),%edi
lea    -0x33(%rbp),%rsi
call   10b0 <write_cmd@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    130c <get_modem_memory+0x14c>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14cb <get_modem_memory+0x30b>
mov    -0x10(%rbp),%rdi
mov    $0x1a4,%esi
call   10e0 <creat@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x35(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %al,-0x34(%rbp)
movsbl -0x34(%rbp),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
movsbl -0x35(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    136b <get_modem_memory+0x1ab>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1485 <get_modem_memory+0x2c5>
movsbl -0x35(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    13d4 <get_modem_memory+0x214>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
mov    %al,-0x34(%rbp)
movsbl -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     13c8 <get_modem_memory+0x208>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x3,-0x4(%rbp)
jmp    14cb <get_modem_memory+0x30b>
movl   $0x1,-0x24(%rbp)
jmp    1480 <get_modem_memory+0x2c0>
cmpl   $0x0,-0x24(%rbp)
jle    142f <get_modem_memory+0x26f>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
mov    %al,-0x34(%rbp)
movsbl -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1428 <get_modem_memory+0x268>
mov    0x2bdc(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x4,-0x4(%rbp)
jmp    14cb <get_modem_memory+0x30b>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x35(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %al,-0x34(%rbp)
movsbl -0x34(%rbp),%eax
cmp    $0x1,%eax
je     147b <get_modem_memory+0x2bb>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
lea    0xbe2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x4,-0x4(%rbp)
jmp    14cb <get_modem_memory+0x30b>
jmp    1480 <get_modem_memory+0x2c0>
jmp    1485 <get_modem_memory+0x2c5>
jmp    148a <get_modem_memory+0x2ca>
cmpl   $0x6,-0x24(%rbp)
jl     131d <get_modem_memory+0x15d>
mov    -0x8(%rbp),%edi
lea    -0x35(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %al,-0x34(%rbp)
movsbl -0x34(%rbp),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_modem_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %edi,%r15d
cmp    $0xff,%dl
je     123c <get_modem_memory+0x8c>
mov    $0x1,%eax
cmp    $0x3f,%dl
jg     13da <get_modem_memory+0x22a>
movw   $0x0,0x3(%rsp)
cmp    $0xa,%dl
jl     11fe <get_modem_memory+0x4e>
movzbl %dl,%eax
imul   $0xcd,%eax,%eax
shr    $0xb,%eax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%dl
or     $0x30,%dl
mov    %dl,0x3(%rsp)
mov    %eax,%edx
add    $0x30,%dl
mov    %dl,0x2(%rsp)
lea    0xe63(%rip),%rsi
lea    0x5(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
lea    0x2(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
jmp    1252 <get_modem_memory+0xa2>
lea    0xe23(%rip),%rsi
lea    0x5(%rsp),%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
lea    0xdae(%rip),%rdi
lea    0x5(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <write_cmd@plt>
test   %eax,%eax
js     1396 <get_modem_memory+0x1e6>
mov    %rbp,%rdi
mov    $0x1a4,%esi
call   10d0 <creat@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
lea    0x1(%rsp),%r12
lea    0xd5b(%rip),%rbx
jmp    12bc <get_modem_memory+0x10c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x6,%ebp
jge    136b <get_modem_memory+0x1bb>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
xor    %edi,%edi
test   %al,%al
setne  %dil
call   1080 <assert@plt>
movzbl 0x1(%rsp),%eax
movslq %ebp,%rcx
cmp    (%rcx,%rbx,1),%al
je     12b0 <get_modem_memory+0x100>
cmp    $0xd,%al
jne    1310 <get_modem_memory+0x160>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
movsbl %al,%eax
cmp    %eax,%ebp
mov    $0x1,%ebp
je     12b3 <get_modem_memory+0x103>
jmp    13b6 <get_modem_memory+0x206>
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    132d <get_modem_memory+0x17d>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
movsbl %al,%eax
cmp    %eax,%ebp
mov    $0x0,%ebp
jne    1345 <get_modem_memory+0x195>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%al
je     12b3 <get_modem_memory+0x103>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0x4,%eax
jmp    13da <get_modem_memory+0x22a>
lea    0x1(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1070 <read@plt>
xor    %edi,%edi
test   %al,%al
sete   %dil
call   1080 <assert@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    13da <get_modem_memory+0x22a>
mov    0x2c43(%rip),%rcx
mov    (%rcx),%edi
lea    0xc88(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%eax
jmp    13da <get_modem_memory+0x22a>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
lea    0xc7c(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0x3,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\0D\0AOK\0D\0A\00"
@.str.1 = [9 x i8] c"at+mtm\0D\00\00"
@.str.2 = [9 x i8] c"at+mtp=\00\00"
@.str.3 = [3 x i8] c"\0D\00\00"
@.str.4 = [39 x i8] c"get_modem_memory: command to send: %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.5 = [20 x i8] c"write_cmd error %d\0A\00"
@.str.6 = [36 x i8] c"error during the write of dumpfile\0A\00"
define i32 @get_modem_memory(i32 %0, i8* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [11 x i8]
%12 = alloca i8
%13 = alloca i8
%14 = alloca [3 x i8]
%15 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %8
store i32 0, i32* %9
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%21 = call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 11)
br label %60
22: ; preds = %3
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = icmp sgt i32 %24, 63
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 1, i32* %4
br label %165
27: ; preds = %22
%28 = bitcast [3 x i8]* %14 to i8*
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 10
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = add nsw i32 48, %34
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
store i8 %36, i8* %37
br label %51
38: ; preds = %27
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
%41 = srem i32 %40, 10
%42 = add nsw i32 48, %41
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 1
store i8 %43, i8* %44
%45 = load i8, i8* %7
%46 = sext i8 %45 to i32
%47 = sdiv i32 %46, 10
%48 = add nsw i32 48, %47
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
store i8 %49, i8* %50
br label %51
51: ; preds = %38, %32
%52 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%53 = call i32 @strncpy(i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 11)
%54 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%55 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%56 = call i32 @strcat(i8* %54, i8* %55)
%57 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %51
br label %60
60: ; preds = %59, %19
%61 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @stdout
%64 = call i32 @fflush(i32 %63)
%65 = load i32, i32* %5
%66 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%67 = call i32 @write_cmd(i32 %65, i8* %66)
store i32 %67, i32* %15
%68 = load i32, i32* %15
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %60
%71 = load i32, i32* @stderr
%72 = load i32, i32* %15
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %72)
store i32 2, i32* %4
br label %165
74: ; preds = %60
%75 = load i8*, i8** %6
%76 = call i32 @creat(i8* %75, i32 420)
store i32 %76, i32* %10
br label %77
77: ; preds = %152, %74
%78 = load i32, i32* %5
%79 = call signext i8 @read(i32 %78, i8* %13, i32 1)
store i8 %79, i8* %12
%80 = load i8, i8* %12
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %81, 0
%83 = zext i1 %82 to i32
%84 = call i32 @assert(i32 %83)
%85 = load i8, i8* %13
%86 = sext i8 %85 to i32
%87 = load i8*, i8** %8
%88 = load i32, i32* %9
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %86, %92
br i1 %93, label %94, label %97
94: ; preds = %77
%95 = load i32, i32* %9
%96 = add nsw i32 %95, 1
store i32 %96, i32* %9
br label %151
97: ; preds = %77
%98 = load i8, i8* %13
%99 = sext i8 %98 to i32
%100 = load i8*, i8** %8
%101 = getelementptr inbounds i8, i8* %100, i64 0
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp eq i32 %99, %103
br i1 %104, label %105, label %120
105: ; preds = %97
%106 = load i32, i32* %10
%107 = load i8*, i8** %8
%108 = load i32, i32* %9
%109 = call signext i8 @write(i32 %106, i8* %107, i32 %108)
store i8 %109, i8* %12
%110 = load i8, i8* %12
%111 = sext i8 %110 to i32
%112 = load i32, i32* %9
%113 = icmp ne i32 %111, %112
br i1 %113, label %114, label %119
114: ; preds = %105
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%117 = load i32, i32* %10
%118 = call i32 @close(i32 %117)
store i32 3, i32* %4
br label %165
119: ; preds = %105
store i32 1, i32* %9
br label %150
120: ; preds = %97
%121 = load i32, i32* %9
%122 = icmp sgt i32 %121, 0
br i1 %122, label %123, label %138
123: ; preds = %120
%124 = load i32, i32* %10
%125 = load i8*, i8** %8
%126 = load i32, i32* %9
%127 = call signext i8 @write(i32 %124, i8* %125, i32 %126)
store i8 %127, i8* %12
%128 = load i8, i8* %12
%129 = sext i8 %128 to i32
%130 = load i32, i32* %9
%131 = icmp ne i32 %129, %130
br i1 %131, label %132, label %137
132: ; preds = %123
%133 = load i32, i32* @stderr
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%135 = load i32, i32* %10
%136 = call i32 @close(i32 %135)
store i32 4, i32* %4
br label %165
137: ; preds = %123
store i32 0, i32* %9
br label %138
138: ; preds = %137, %120
%139 = load i32, i32* %10
%140 = call signext i8 @write(i32 %139, i8* %13, i32 1)
store i8 %140, i8* %12
%141 = load i8, i8* %12
%142 = sext i8 %141 to i32
%143 = icmp ne i32 %142, 1
br i1 %143, label %144, label %149
144: ; preds = %138
%145 = load i32, i32* @stderr
%146 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%147 = load i32, i32* %10
%148 = call i32 @close(i32 %147)
store i32 4, i32* %4
br label %165
149: ; preds = %138
br label %150
150: ; preds = %149, %119
br label %151
151: ; preds = %150, %94
br label %152
152: ; preds = %151
%153 = load i32, i32* %9
%154 = icmp slt i32 %153, 6
br i1 %154, label %77, label %155
155: ; preds = %152
%156 = load i32, i32* %5
%157 = call signext i8 @read(i32 %156, i8* %13, i32 1)
store i8 %157, i8* %12
%158 = load i8, i8* %12
%159 = sext i8 %158 to i32
%160 = icmp eq i32 %159, 0
%161 = zext i1 %160 to i32
%162 = call i32 @assert(i32 %161)
%163 = load i32, i32* %10
%164 = call i32 @close(i32 %163)
store i32 0, i32* %4
br label %165
165: ; preds = %155, %144, %132, %114, %70, %26
%166 = load i32, i32* %4
ret i32 %166
}

LLVM IR (-O2):
@.str = [7 x i8] c"\0D\0AOK\0D\0A\00"
@.str.1 = [9 x i8] c"at+mtm\0D\00\00"
@.str.2 = [9 x i8] c"at+mtp=\00\00"
@.str.3 = [3 x i8] c"\0D\00\00"
@.str.4 = [39 x i8] c"get_modem_memory: command to send: %s\0A\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.5 = [20 x i8] c"write_cmd error %d\0A\00"
@.str.6 = [36 x i8] c"error during the write of dumpfile\0A\00"
define i32 @get_modem_memory(i32 %0, i8* %1, i8 signext %2) {
%4 = alloca [11 x i8]
%5 = alloca i8
%6 = alloca [3 x i8]
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%8 = icmp eq i8 %2, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 11)
br label %29
11: ; preds = %3
%12 = icmp sgt i8 %2, 63
br i1 %12, label %90, label %13
13: ; preds = %11
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
%16 = bitcast i8* %15 to i16*
store i16 0, i16* %16
%17 = icmp slt i8 %2, 10
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = urem i8 %2, 10
%20 = or i8 %19, 48
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %20, i8* %21
%22 = udiv i8 %2, 10
br label %23
23: ; preds = %13, %18
%24 = phi i8 [ %22, %18 ], [ %2, %13 ]
%25 = add nsw i8 %24, 48
store i8 %25, i8* %14
%26 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 11)
%27 = call i32 @strcat(i8* %7, i8* %14)
%28 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %23, %9
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = call i32 @write_cmd(i32 %0, i8* %7)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %33)
br label %90
38: ; preds = %29
%39 = call i32 @creat(i8* %1, i32 420)
br label %40
40: ; preds = %81, %38
%41 = phi i32 [ 0, %38 ], [ %82, %81 ]
%42 = call signext i8 @read(i32 %0, i8* %5, i32 1)
%43 = icmp ne i8 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i8, i8* %5
%47 = sext i32 %41 to i64
%48 = getelementptr inbounds [7 x i8], [7 x i8]* @.str, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %46, %49
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = add nsw i32 %41, 1
br label %81
53: ; preds = %40
%54 = icmp eq i8 %46, 13
br i1 %54, label %55, label %63
55: ; preds = %53
%56 = call signext i8 @write(i32 %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %41, %57
br i1 %58, label %81, label %59
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%62 = call i32 @close(i32 %39)
br label %90
63: ; preds = %53
%64 = icmp sgt i32 %41, 0
br i1 %64, label %65, label %73
65: ; preds = %63
%66 = call signext i8 @write(i32 %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %41, %67
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%72 = call i32 @close(i32 %39)
br label %90
73: ; preds = %65, %63
%74 = phi i32 [ %41, %63 ], [ 0, %65 ]
%75 = call signext i8 @write(i32 %39, i8* %5, i32 1)
%76 = icmp eq i8 %75, 1
br i1 %76, label %81, label %77
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%80 = call i32 @close(i32 %39)
br label %90
81: ; preds = %55, %51, %73
%82 = phi i32 [ %52, %51 ], [ %74, %73 ], [ 1, %55 ]
%83 = icmp slt i32 %82, 6
br i1 %83, label %40, label %84
84: ; preds = %81
%85 = call signext i8 @read(i32 %0, i8* %5, i32 1)
%86 = icmp eq i8 %85, 0
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = call i32 @close(i32 %39)
br label %90
90: ; preds = %35, %59, %69, %77, %84, %11
%91 = phi i32 [ 1, %11 ], [ 2, %35 ], [ 0, %84 ], [ 3, %59 ], [ 4, %69 ], [ 4, %77 ]
ret i32 %91
}