#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int zapisz(FILE *p, int obraz_pgm[][512], int wymx, int wymy, int szarosci) {
  char s[80];
  int znak, koniec = 0, i, j;
  if (p == NULL) {
    fprintf(stderr, "Blad: Nie podano uchwytu do pliku.\n");
    return 0;
  }
  fputs("P2\n", p);
  sprintf(s, "%d ", wymx);
  fputs(s, p);
  sprintf(s, "%d\n", wymy);
  fputs(s, p);
  sprintf(s, "%d\n", szarosci);
  fputs(s, p);
  for (i = 0; i < wymy; i++) {
    for (j = 0; j < wymx; j++) {
      sprintf(s, "%d ", obraz_pgm[i][j]);
      fputs(s, p);
    }
    fputs("\n", p);
  }
  return wymx * wymy;
}


x86 assembly (clang, -O0):
<zapisz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x88(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <zapisz+0x53>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <zapisz+0x170>
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1030 <fputs@plt>
lea    -0x80(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe87(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe6b(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
lea    -0x80(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe4b(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1296 <zapisz+0x166>
movl   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1272 <zapisz+0x142>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x8c(%rbp),%rcx
shl    $0xb,%rcx
add    %rcx,%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xddc(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    1216 <zapisz+0xe6>
mov    -0x10(%rbp),%rsi
lea    0xda5(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    11fd <zapisz+0xcd>
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zapisz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
test   %rdi,%rdi
je     1290 <zapisz+0x140>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xeab(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r13,%rcx
mov    %r8d,0x10(%rsp)
call   1070 <fwrite@plt>
lea    0xe91(%rip),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,0x8(%rsp)
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
lea    0xe70(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%edx
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
mov    %r14d,0xc(%rsp)
test   %r14d,%r14d
jle    1285 <zapisz+0x135>
mov    0xc(%rsp),%eax
mov    %rax,0x18(%rsp)
mov    0x8(%rsp),%r15d
xor    %eax,%eax
lea    0xe14(%rip),%r12
lea    0x20(%rsp),%rbp
jmp    1244 <zapisz+0xf4>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
mov    0x10(%rsp),%rax
add    $0x1,%rax
add    $0x800,%rbx
cmp    0x18(%rsp),%rax
je     1285 <zapisz+0x135>
mov    %rax,0x10(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    1220 <zapisz+0xd0>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%r14,4),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <sprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
add    $0x1,%r14
cmp    %r14,%r15
jne    1260 <zapisz+0x110>
jmp    1220 <zapisz+0xd0>
mov    0xc(%rsp),%eax
imul   0x8(%rsp),%eax
jmp    12a7 <zapisz+0x157>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Blad: Nie podano uchwytu do pliku.\0A\00"
@.str.1 = [4 x i8] c"P2\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @zapisz(i32* %0, [512 x i32]* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [512 x i32]*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [80 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %7
store [512 x i32]* %1, [512 x i32]** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %14
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %79
22: ; preds = %5
%23 = load i32*, i32** %7
%24 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%26 = load i32, i32* %9
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%29 = load i32*, i32** %7
%30 = call i32 @fputs(i8* %28, i32* %29)
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%32 = load i32, i32* %10
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%35 = load i32*, i32** %7
%36 = call i32 @fputs(i8* %34, i32* %35)
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%38 = load i32, i32* %11
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%41 = load i32*, i32** %7
%42 = call i32 @fputs(i8* %40, i32* %41)
store i32 0, i32* %15
br label %43
43: ; preds = %72, %22
%44 = load i32, i32* %15
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %75
47: ; preds = %43
store i32 0, i32* %16
br label %48
48: ; preds = %66, %47
%49 = load i32, i32* %16
%50 = load i32, i32* %9
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %69
52: ; preds = %48
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%54 = load [512 x i32]*, [512 x i32]** %8
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [512 x i32], [512 x i32]* %54, i64 %56
%58 = load i32, i32* %16
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [512 x i32], [512 x i32]* %57, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%64 = load i32*, i32** %7
%65 = call i32 @fputs(i8* %63, i32* %64)
br label %66
66: ; preds = %52
%67 = load i32, i32* %16
%68 = add nsw i32 %67, 1
store i32 %68, i32* %16
br label %48
69: ; preds = %48
%70 = load i32*, i32** %7
%71 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %15
%74 = add nsw i32 %73, 1
store i32 %74, i32* %15
br label %43
75: ; preds = %43
%76 = load i32, i32* %9
%77 = load i32, i32* %10
%78 = mul nsw i32 %76, %77
store i32 %78, i32* %6
br label %79
79: ; preds = %75, %19
%80 = load i32, i32* %6
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Blad: Nie podano uchwytu do pliku.\0A\00"
@.str.1 = [4 x i8] c"P2\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @zapisz(i32* %0, [512 x i32]* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [80 x i8]
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%8 = icmp eq i32* %0, null
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %41
12: ; preds = %5
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 3, i64 1, i32* %0)
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%15 = call i32 @fputs(i8* %7, i32* %0)
%16 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%17 = call i32 @fputs(i8* %7, i32* %0)
%18 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %4)
%19 = call i32 @fputs(i8* %7, i32* %0)
%20 = icmp sgt i32 %3, 0
br i1 %20, label %21, label %39
21: ; preds = %12
%22 = icmp sgt i32 %2, 0
%23 = zext i32 %3 to i64
%24 = zext i32 %2 to i64
br label %25
25: ; preds = %21, %35
%26 = phi i64 [ 0, %21 ], [ %37, %35 ]
br i1 %22, label %27, label %35
27: ; preds = %25, %27
%28 = phi i64 [ %33, %27 ], [ 0, %25 ]
%29 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 @fputs(i8* %7, i32* %0)
%33 = add nuw nsw i64 %28, 1
%34 = icmp eq i64 %33, %24
br i1 %34, label %35, label %27
35: ; preds = %27, %25
%36 = tail call i32 @fputc(i32 10, i32* %0)
%37 = add nuw nsw i64 %26, 1
%38 = icmp eq i64 %37, %23
br i1 %38, label %39, label %25
39: ; preds = %35, %12
%40 = mul nsw i32 %3, %2
br label %41
41: ; preds = %39, %9
%42 = phi i32 [ 0, %9 ], [ %40, %39 ]
ret i32 %42
}