#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int set_bitpix(char *buf, int ptype) {
  char *where;
  char replace[81];
  where = strstr(buf, "BITPIX");
  if (where == NULL) {
    fprintf(stderr, "cannot find BITPIX in header: aborting\n");
    return -1;
  }
  sprintf(replace,
          "BITPIX  =                  % 3d / Bits per pixel                    "
          "             ",
          ptype);
  memcpy(where, replace, 80);
  return 0;
}


x86 assembly (clang, -O0):
<set_bitpix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1192 <set_bitpix+0x52>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <set_bitpix+0x7e>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe8f(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_bitpix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %esi,%ebp
lea    0xeaf(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1186 <set_bitpix+0x46>
mov    %rax,%rbx
lea    0xeca(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
jmp    11a0 <set_bitpix+0x60>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"BITPIX\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"cannot find BITPIX in header: aborting\0A\00"
@.str.2 = [82 x i8] c"BITPIX = % 3d / Bits per pixel \00"
define i32 @set_bitpix(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [81 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %22
15: ; preds = %2
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 80)
store i32 0, i32* %3
br label %22
22: ; preds = %15, %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"BITPIX\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"cannot find BITPIX in header: aborting\0A\00"
@.str.2 = [82 x i8] c"BITPIX = % 3d / Bits per pixel \00"
define i32 @set_bitpix(i8* %0, i32 %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %2
%11 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%12 = call i32 @memcpy(i8* %5, i8* %4, i32 80)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ -1, %7 ], [ 0, %10 ]
ret i32 %14
}