#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 O_CREAT;
int O_RDWR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buff[100];
  int num;
  int i, j;
  int m, n;
  if (argc < 4) {
    printf("Usage:  ./mat 5 8 out.txt\n");
    return -1;
  }
  n = atoi(argv[1]);
  m = atoi(argv[2]);
  int fout = open(argv[3], O_CREAT | O_RDWR, 0640);
  if (fout < 0)
    return -1;
  sprintf(buff, "%d %d\n", n, m);
  write(fout, buff, strlen(buff));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      num = rand() % 10;
      sprintf(buff, "%d ", num);
      write(fout, buff, strlen(buff));
    }
    sprintf(buff, "\n", num);
    write(fout, buff, strlen(buff));
  }
  close(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1395 <main+0x215>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1070 <open@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jge    1224 <main+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1395 <main+0x215>
lea    -0x80(%rbp),%rdi
mov    -0x94(%rbp),%edx
mov    -0x90(%rbp),%ecx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0xa4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x94(%rbp),%eax
jge    1383 <main+0x203>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x90(%rbp),%eax
jge    1323 <main+0x1a3>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    129c <main+0x11c>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
lea    0xcec(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0xc4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1280 <main+0x100>
mov    -0x98(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x3,%edi
jg     11a4 <main+0x24>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
jmp    12e5 <main+0x165>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
mov    0x2e2f(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a0,%edx
call   1070 <open@plt>
test   %eax,%eax
js     12e5 <main+0x165>
mov    %eax,%ebx
lea    0xe11(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r12d,%edx
mov    %ebp,0x8(%rsp)
mov    %ebp,%ecx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %r12d,%r12d
jle    12ec <main+0x16c>
lea    0xddc(%rip),%r13
lea    0x10(%rsp),%rbp
xor    %r15d,%r15d
mov    %r12d,0xc(%rsp)
jmp    1276 <main+0xf6>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xdbb(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
add    $0x1,%r15d
mov    0xc(%rsp),%r12d
cmp    %r12d,%r15d
je     12ec <main+0x16c>
cmpl   $0x0,0x8(%rsp)
jle    1240 <main+0xc0>
mov    0x8(%rsp),%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%r14
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r14d
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
add    $0xffffffff,%r12d
jne    1290 <main+0x110>
jmp    1240 <main+0xc0>
mov    $0xffffffff,%eax
jmp    12f5 <main+0x175>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: ./mat 5 8 out.txt\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %84
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %11
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %10
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_CREAT
%30 = load i32, i32* @O_RDWR
%31 = or i32 %29, %30
%32 = call i32 @open(i8* %28, i32 %31, i32 416)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %17
store i32 -1, i32* %3
br label %84
36: ; preds = %17
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %11
%39 = load i32, i32* %10
%40 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
%41 = load i32, i32* %12
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @write(i32 %41, i8* %42, i32 %44)
store i32 0, i32* %8
br label %46
46: ; preds = %78, %36
%47 = load i32, i32* %8
%48 = load i32, i32* %11
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %81
50: ; preds = %46
store i32 0, i32* %9
br label %51
51: ; preds = %66, %50
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %69
55: ; preds = %51
%56 = call i32 (...) @rand()
%57 = srem i32 %56, 10
store i32 %57, i32* %7
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%59 = load i32, i32* %7
%60 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %12
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @write(i32 %61, i8* %62, i32 %64)
br label %66
66: ; preds = %55
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %51
69: ; preds = %51
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* %7
%72 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %12
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%76 = call i32 @strlen(i8* %75)
%77 = call i32 @write(i32 %73, i8* %74, i32 %76)
br label %78
78: ; preds = %69
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %46
81: ; preds = %46
%82 = load i32, i32* %12
%83 = call i32 @close(i32 %82)
store i32 0, i32* %3
br label %84
84: ; preds = %81, %35, %15
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
@str = [26 x i8] c"Usage: ./mat 5 8 out.txt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %50
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_RDWR
%19 = or i32 %18, %17
%20 = tail call i32 @open(i8* %16, i32 %19, i32 416)
%21 = icmp slt i32 %20, 0
br i1 %21, label %50, label %22
22: ; preds = %8
%23 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
%24 = call i32 @strlen(i8* %4)
%25 = call i32 @write(i32 %20, i8* %4, i32 %24)
%26 = icmp sgt i32 %11, 0
br i1 %26, label %27, label %48
27: ; preds = %22
%28 = icmp sgt i32 %14, 0
br label %29
29: ; preds = %27, %41
%30 = phi i32 [ undef, %27 ], [ %42, %41 ]
%31 = phi i32 [ 0, %27 ], [ %46, %41 ]
br i1 %28, label %32, label %41
32: ; preds = %29, %32
%33 = phi i32 [ %39, %32 ], [ 0, %29 ]
%34 = call i32 (...) @rand()
%35 = srem i32 %34, 10
%36 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @strlen(i8* %4)
%38 = call i32 @write(i32 %20, i8* %4, i32 %37)
%39 = add nuw nsw i32 %33, 1
%40 = icmp eq i32 %39, %14
br i1 %40, label %41, label %32
41: ; preds = %32, %29
%42 = phi i32 [ %30, %29 ], [ %35, %32 ]
%43 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = call i32 @strlen(i8* %4)
%45 = call i32 @write(i32 %20, i8* %4, i32 %44)
%46 = add nuw nsw i32 %31, 1
%47 = icmp eq i32 %46, %11
br i1 %47, label %48, label %29
48: ; preds = %41, %22
%49 = call i32 @close(i32 %20)
br label %50
50: ; preds = %48, %8, %6
%51 = phi i32 [ -1, %6 ], [ 0, %48 ], [ -1, %8 ]
ret i32 %51
}