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

/* Variables and functions */
int /*<<< orphan*/ Log(int, char *, char *);
int /*<<< orphan*/ bzero(char *, int);
int i2c_ASN1_INTEGER(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void grid_printSerial(ASN1_INTEGER *certSerial) {
  int i, serialLen;
  unsigned char serialNumberDER[127];
  unsigned char *serialNumberPtr = serialNumberDER;
  char serialStr[255];
  char *serialStrPtr = serialStr;
  serialLen = i2c_ASN1_INTEGER(certSerial, &serialNumberPtr);
  bzero(serialStr, sizeof(serialStr));
  for (i = 0; i < serialLen; i++) {
    sprintf(serialStrPtr, "%02X", serialNumberDER[i]);
    serialStrPtr = serialStrPtr + 2;
  }
  Log(3, "Serial number: %s", serialStr);
}


x86 assembly (clang, -O0):
<grid_printSerial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x1a0(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x98(%rbp),%rsi
call   1060 <i2c_ASN1_INTEGER@plt>
mov    %eax,-0x10(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    $0xff,%esi
call   1040 <bzero@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e1 <grid_printSerial+0xa1>
mov    -0x1a8(%rbp),%rdi
movslq -0xc(%rbp),%rax
lea    0xe4c(%rip),%rsi
movzbl -0x90(%rbp,%rax,1),%edx
ff
call   1050 <sprintf@plt>
mov    -0x1a8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x1a8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1196 <grid_printSerial+0x56>
lea    -0x1a0(%rbp),%rdx
mov    $0x3,%edi
lea    0xe11(%rip),%rsi
call   1030 <Log@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_printSerial>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x198,%rsp
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1060 <i2c_ASN1_INTEGER@plt>
mov    %eax,%ebp
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1040 <bzero@plt>
test   %ebp,%ebp
jle    11ad <grid_printSerial+0x6d>
mov    %ebp,%r15d
xor    %ebp,%ebp
lea    0xe78(%rip),%r14
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
add    $0x2,%rbx
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1190 <grid_printSerial+0x50>
lea    0xe51(%rip),%rsi
lea    0x90(%rsp),%rdx
mov    $0x3,%edi
call   1030 <Log@plt>
add    $0x198,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
@.str.1 = [18 x i8] c"Serial number: %s\00"
define void @grid_printSerial(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [127 x i8]
%6 = alloca i8*
%7 = alloca [255 x i8]
%8 = alloca i8*
store i32* %0, i32** %2
%9 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 0
store i8* %9, i8** %6
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
store i8* %10, i8** %8
%11 = load i32*, i32** %2
%12 = call i32 @i2c_ASN1_INTEGER(i32* %11, i8** %6)
store i32 %12, i32* %4
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 255)
store i32 0, i32* %3
br label %15
15: ; preds = %28, %1
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i8*, i8** %8
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [127 x i8], [127 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %8
br label %28
28: ; preds = %19
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %15
31: ; preds = %15
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%33 = call i32 @Log(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
@.str.1 = [18 x i8] c"Serial number: %s\00"
define void @grid_printSerial(i32* %0) {
%2 = alloca [127 x i8]
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 0
%6 = bitcast i8** %3 to i8*
store i8* %5, i8** %3
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = call i32 @i2c_ASN1_INTEGER(i32* %0, i8** %3)
%9 = call i32 @bzero(i8* %7, i32 255)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = phi i8* [ %7, %11 ], [ %19, %13 ]
%16 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 %14
%17 = load i8, i8* %16
%18 = call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
%19 = getelementptr inbounds i8, i8* %15, i64 2
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13, %1
%23 = call i32 @Log(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %7)
ret void
}