#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 */
struct ppm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EncodeMessage(struct ppm *, char *);
int /*<<< orphan*/ FatalError(char *);
int /*<<< orphan*/ Warning(char *);
int /*<<< orphan*/ free(struct ppm *);
struct ppm *ppm_read(char *);
scalar_t__ ppm_write(struct ppm *, char *);
int /*<<< orphan*/ showHelp();
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc == 2 && (strcmp(argv[1], "-help") == 0)) {
    showHelp();
    return 0;
  }
  if (argc != 4) {
    Warning("Zle zadane argumenty\n");
    showHelp();
    return 1;
  }
  struct ppm *ppmFile = ppm_read(argv[1]);
  if (ppmFile == NULL) {
    FatalError("Chyba citania zo suboru");
    return 1;
  }
  EncodeMessage(ppmFile, argv[3]);
  if (ppm_write(ppmFile, argv[2]) != 0) {
    free(ppmFile);
    Warning("Zapis do suboru sa nepodaril");
    return 1;
  }
  free(ppmFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11d1 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x51>
mov    $0x0,%al
call   1030 <showHelp@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <main+0x10b>
cmpl   $0x4,-0x8(%rbp)
je     11fa <main+0x7a>
lea    0xe24(%rip),%rdi
call   1070 <Warning@plt>
mov    $0x0,%al
call   1030 <showHelp@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <ppm_read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122e <main+0xae>
lea    0xdff(%rip),%rdi
call   1080 <FatalError@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x10b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   10a0 <EncodeMessage@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <ppm_write@plt>
cmp    $0x0,%rax
je     127b <main+0xfb>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
lea    0xdca(%rip),%rdi
call   1070 <Warning@plt>
movl   $0x1,-0x4(%rbp)
jmp    128b <main+0x10b>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
je     11c8 <main+0x48>
cmp    $0x2,%edi
jne    11a6 <main+0x26>
mov    0x8(%rbx),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120f <main+0x8f>
lea    0xe59(%rip),%rdi
call   1070 <Warning@plt>
xor    %eax,%eax
call   1030 <showHelp@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rbx),%rdi
call   1090 <ppm_read@plt>
test   %rax,%rax
je     121a <main+0x9a>
mov    %rax,%r14
mov    0x18(%rbx),%rsi
mov    %rax,%rdi
call   10a0 <EncodeMessage@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
call   1060 <ppm_write@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <free@plt>
test   %rbx,%rbx
je     1228 <main+0xa8>
lea    0xe2c(%rip),%rdi
call   1070 <Warning@plt>
jmp    11b9 <main+0x39>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <showHelp@plt>
jmp    11be <main+0x3e>
lea    0xdfb(%rip),%rdi
call   1080 <FatalError@plt>
jmp    11b9 <main+0x39>
xor    %ebx,%ebx
jmp    11be <main+0x3e>

LLVM IR (-O0):
%struct.ppm = type { i32 }
@.str = [6 x i8] c"-help\00"
@.str.1 = [22 x i8] c"Zle zadane argumenty\0A\00"
@.str.2 = [24 x i8] c"Chyba citania zo suboru\00"
@.str.3 = [29 x i8] c"Zapis do suboru sa nepodaril\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ppm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (...) @showHelp()
store i32 0, i32* %3
br label %51
17: ; preds = %9, %2
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @Warning(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @showHelp()
store i32 1, i32* %3
br label %51
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call %struct.ppm* @ppm_read(i8* %26)
store %struct.ppm* %27, %struct.ppm** %6
%28 = load %struct.ppm*, %struct.ppm** %6
%29 = icmp eq %struct.ppm* %28, null
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @FatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %51
32: ; preds = %23
%33 = load %struct.ppm*, %struct.ppm** %6
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @EncodeMessage(%struct.ppm* %33, i8* %36)
%38 = load %struct.ppm*, %struct.ppm** %6
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i64 @ppm_write(%struct.ppm* %38, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %32
%45 = load %struct.ppm*, %struct.ppm** %6
%46 = call i32 @free(%struct.ppm* %45)
%47 = call i32 @Warning(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %51
48: ; preds = %32
%49 = load %struct.ppm*, %struct.ppm** %6
%50 = call i32 @free(%struct.ppm* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %48, %44, %30, %20, %15
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.ppm = type { i32 }
@.str = [6 x i8] c"-help\00"
@.str.1 = [22 x i8] c"Zle zadane argumenty\0A\00"
@.str.2 = [24 x i8] c"Chyba citania zo suboru\00"
@.str.3 = [29 x i8] c"Zapis do suboru sa nepodaril\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %10 [
i32 2, label %3
i32 4, label %13
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (...) @showHelp()
br label %31
10: ; preds = %3, %2
%11 = tail call i32 @Warning(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (...) @showHelp()
br label %31
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call %struct.ppm* @ppm_read(i8* %15)
%17 = icmp eq %struct.ppm* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @FatalError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %31
20: ; preds = %13
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @EncodeMessage(%struct.ppm* %16, i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i64 @ppm_write(%struct.ppm* %16, i8* %25)
%27 = icmp eq i64 %26, 0
%28 = tail call i32 @free(%struct.ppm* %16)
br i1 %27, label %31, label %29
29: ; preds = %20
%30 = tail call i32 @Warning(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %20, %18, %29, %10, %8
%32 = phi i32 [ 0, %8 ], [ 1, %10 ], [ 1, %18 ], [ 1, %29 ], [ 0, %20 ]
ret i32 %32
}