#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*/ printf(char *, char, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
int string_2_hex(char *buff, char *new_buff) {
  int temp;
  char temp_buff[2];
  int i = 0, j = 0;
  for (i = 0; i < strlen(buff); i = i + 2) {
    if (buff[i] == '#')
      break;
    temp_buff[0] = buff[i];
    temp_buff[1] = buff[i + 1];
    printf("temp_buff[0] = %c, temp_buff[1] = %c\n", temp_buff[0],
           temp_buff[1]);
    sscanf(temp_buff, "%x", &temp);
    printf("temp = %i\n", temp);
    new_buff[j] = temp;
    printf("new_buff[] = %c\n", new_buff[j]);
    j++;
  }
  new_buff[j + 1] = '#';
  new_buff[j + 2] = '#';
  return 0;
}


x86 assembly (clang, -O0):
<string_2_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    122d <string_2_hex+0xfd>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
jne    118b <string_2_hex+0x5b>
jmp    122d <string_2_hex+0xfd>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x16(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x16(%rbp),%al
movsbl -0x15(%rbp),%edx
lea    0xe46(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x16(%rbp),%rdi
lea    0xe57(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%eax
lea    0xe47(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe29(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <string_2_hex+0x25>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x23,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x23,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_2_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    11e4 <string_2_hex+0xb4>
lea    0xed4(%rip),%r15
lea    0xed8(%rip),%r12
xor    %ebp,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
cmp    $0x23,%al
je     11e7 <string_2_hex+0xb7>
mov    %al,0x2(%rsp)
movsbl 0x1(%rbx,%rbp,1),%edx
mov    %dl,0x3(%rsp)
movsbl %al,%esi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x2(%rsp),%rdi
lea    0xe84(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
movsbl 0x4(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x4(%rsp),%esi
mov    %sil,(%r14,%r13,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
add    $0x2,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jg     1170 <string_2_hex+0x40>
jmp    11e7 <string_2_hex+0xb7>
xor    %r13d,%r13d
mov    %r13d,%eax
movw   $0x2323,0x1(%rax,%r14,1)
23
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"temp_buff[0] = %c, temp_buff[1] = %c\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [11 x i8] c"temp = %i\0A\00"
@.str.3 = [17 x i8] c"new_buff[] = %c\0A\00"
define i32 @string_2_hex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %62, %2
%10 = load i32, i32* %7
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %65
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 35
br i1 %21, label %22, label %23
22: ; preds = %14
br label %65
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %28, i8* %29
%30 = load i8*, i8** %3
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %35, i8* %36
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%38 = load i8, i8* %37
%39 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8 signext %38, i32 %41)
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%45 = load i32, i32* %5
%46 = trunc i32 %45 to i8
%47 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 signext %46)
%48 = load i32, i32* %5
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %4
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 %49, i8* %53
%54 = load i8*, i8** %4
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext %58)
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %62
62: ; preds = %23
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 2
store i32 %64, i32* %7
br label %9
65: ; preds = %22, %9
%66 = load i8*, i8** %4
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
store i8 35, i8* %70
%71 = load i8*, i8** %4
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %71, i64 %74
store i8 35, i8* %75
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"temp_buff[0] = %c, temp_buff[1] = %c\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [11 x i8] c"temp = %i\0A\00"
@.str.3 = [17 x i8] c"new_buff[] = %c\0A\00"
define i32 @string_2_hex(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %39
9: ; preds = %2
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %11
11: ; preds = %9, %17
%12 = phi i64 [ 0, %9 ], [ %32, %17 ]
%13 = phi i64 [ 0, %9 ], [ %31, %17 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 35
br i1 %16, label %36, label %17
17: ; preds = %11
store i8 %15, i8* %6
%18 = or i64 %12, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %10
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8 signext %15, i32 %21)
%23 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
%26 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 signext %25)
%27 = load i32, i32* %3
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %28, i8* %29
%30 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext %28)
%31 = add nuw i64 %13, 1
%32 = add nuw i64 %12, 2
%33 = call i32 @strlen(i8* %0)
%34 = trunc i64 %32 to i32
%35 = icmp sgt i32 %33, %34
br i1 %35, label %11, label %36
36: ; preds = %11, %17
%37 = phi i64 [ %31, %17 ], [ %13, %11 ]
%38 = trunc i64 %37 to i32
br label %39
39: ; preds = %36, %2
%40 = phi i32 [ 0, %2 ], [ %38, %36 ]
%41 = add nuw nsw i32 %40, 1
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %1, i64 %42
store i8 35, i8* %43
%44 = add nuw nsw i32 %40, 2
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %1, i64 %45
store i8 35, i8* %46
ret i32 0
}