#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_gif_info(char *);
int /*<<< orphan*/ set_gif_comment(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ validate_gif_structure(char *);
int main(int argc, char **argv) {
  char *progname;
  char *filename;
  char *comment;
  FILE *fp;
  int error;
  progname = argv[0];
  if (progname == NULL || progname[0] == 0)
    progname = "gif-info";
  if (argc < 2 || argc > 3) {
    fprintf(stderr,
            "Usage: %s <filename> [\"<comment>\"]\nReads gif image info or "
            "sets comment.\n",
            progname);
    return (5);
  }
  filename = argv[1];
  comment = argv[2];
  if ((fp = fopen(filename, "rb")) == NULL) {
    fprintf(stderr, "Error: Can't open file '%s'\n", filename);
    return (5);
  }
  fclose(fp);
  if (validate_gif_structure(filename)) {
    fprintf(stderr, "Error: error parsing file '%s' as a gif image\n",
            filename);
    return (5);
  }
  if (argc == 2) {
    get_gif_info(filename);
  } else {
    set_gif_comment(filename, comment);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119c <main+0x3c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a7 <main+0x47>
lea    0xe5d(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11bb <main+0x5b>
cmpl   $0x3,-0x8(%rbp)
jle    11e0 <main+0x80>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12a8 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    123b <main+0xdb>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12a8 <main+0x148>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <validate_gif_structure@plt>
cmp    $0x0,%rax
je     127c <main+0x11c>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12a8 <main+0x148>
cmpl   $0x2,-0x8(%rbp)
jne    1294 <main+0x134>
mov    -0x20(%rbp),%rdi
call   1030 <get_gif_info@plt>
jmp    12a1 <main+0x141>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <set_gif_comment@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    (%rsi),%rdx
test   %rdx,%rdx
je     1174 <main+0x14>
cmpb   $0x0,(%rdx)
jne    117b <main+0x1b>
lea    0xe85(%rip),%rdx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     1195 <main+0x35>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
jmp    11eb <main+0x8b>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
lea    0xeaf(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d8 <main+0x78>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1040 <validate_gif_structure@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
jmp    11e8 <main+0x88>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x5,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
cmp    $0x2,%ebx
jne    120a <main+0xaa>
call   1030 <get_gif_info@plt>
jmp    1212 <main+0xb2>
mov    %r15,%rsi
call   1060 <set_gif_comment@plt>
xor    %eax,%eax
jmp    11f5 <main+0x95>

LLVM IR (-O0):
@.str = [9 x i8] c"gif-info\00"
@stderr = global i32 0
@.str.1 = [74 x i8] c"Usage: %s <filename> [\22<comment>\22]\0AReads gif image info or sets comment.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [29 x i8] c"Error: Can't open file '%s'\0A\00"
@.str.4 = [47 x i8] c"Error: error parsing file '%s' as a gif image\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16, %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
br label %23
23: ; preds = %22, %16
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 3
br i1 %28, label %29, label %33
29: ; preds = %26, %23
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i32 5, i32* %3
br label %68
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
store i8* %36, i8** %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %8
%40 = load i8*, i8** %7
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %9
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %47
43: ; preds = %33
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %7
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %45)
store i32 5, i32* %3
br label %68
47: ; preds = %33
%48 = load i32*, i32** %9
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %7
%51 = call i64 @validate_gif_structure(i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %7
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %55)
store i32 5, i32* %3
br label %68
57: ; preds = %47
%58 = load i32, i32* %4
%59 = icmp eq i32 %58, 2
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i8*, i8** %7
%62 = call i32 @get_gif_info(i8* %61)
br label %67
63: ; preds = %57
%64 = load i8*, i8** %7
%65 = load i8*, i8** %8
%66 = call i32 @set_gif_comment(i8* %64, i8* %65)
br label %67
67: ; preds = %63, %60
store i32 0, i32* %3
br label %68
68: ; preds = %67, %53, %43, %29
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [9 x i8] c"gif-info\00"
@stderr = global i32 0
@.str.1 = [74 x i8] c"Usage: %s <filename> [\22<comment>\22]\0AReads gif image info or sets comment.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [29 x i8] c"Error: Can't open file '%s'\0A\00"
@.str.4 = [47 x i8] c"Error: error parsing file '%s' as a gif image\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %5, %2
br label %9
9: ; preds = %8, %5
%10 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %8 ], [ %3, %5 ]
%11 = add i32 %0, -4
%12 = icmp ult i32 %11, -2
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %39
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %39
26: ; preds = %16
%27 = tail call i32 @fclose(i32* %21)
%28 = tail call i64 @validate_gif_structure(i8* %18)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %18)
br label %39
33: ; preds = %26
%34 = icmp eq i32 %0, 2
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = tail call i32 @get_gif_info(i8* %18)
br label %39
37: ; preds = %33
%38 = tail call i32 @set_gif_comment(i8* %18, i8* %20)
br label %39
39: ; preds = %35, %37, %30, %23, %13
%40 = phi i32 [ 5, %13 ], [ 5, %23 ], [ 5, %30 ], [ 0, %37 ], [ 0, %35 ]
ret i32 %40
}