#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 sscanf(char *, char *, int *, int *, int *, int *);
int /*<<< orphan*/ stdout;
void process_buffer(char *buf, int buf_size) {
  int num[4];
  int res;
  int cont;
  buf[buf_size] = '\0';
  (void)fprintf(stdout, "\nread %d characters = \"%s\"\n", buf_size, buf);
  res =
      sscanf(buf, "%x %x %x %x\n", &(num[0]), &(num[1]), &(num[2]), &(num[3]));
  (void)fprintf(stdout, "...converted %d exadecimal integer(s)", res);
  if (res > 0) {
    (void)fprintf(stdout, ": ");
    for (cont = 0; cont < res; cont++)
      (void)fprintf(stdout, "%x ", num[cont]);
    (void)fprintf(stdout, "\n");
  }
}


x86 assembly (clang, -O0):
<process_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xe9c(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x24(%rbp)
jle    121a <process_buffer+0xfa>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1203 <process_buffer+0xe3>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ca <process_buffer+0xaa>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movslq %esi,%rdx
movb   $0x0,(%rdi,%rdx,1)
mov    0x2ea4(%rip),%r14
mov    (%r14),%edi
lea    0xeba(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xeb6(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    %eax,%ebx
mov    (%r14),%edi
lea    0xeac(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %ebx,%ebx
jle    11da <process_buffer+0xba>
mov    (%r14),%edi
lea    0xebb(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%r12d
lea    0xead(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    (%rsp,%rbx,4),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11b0 <process_buffer+0x90>
mov    (%r14),%edi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [28 x i8] c"\0Aread %d characters = \22%s\22\0A\00"
@.str.1 = [13 x i8] c"%x %x %x %x\0A\00"
@.str.2 = [38 x i8] c"...converted %d exadecimal integer(s)\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [4 x i8] c"%x \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @process_buffer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4 x i32]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* @stdout
%13 = load i32, i32* %4
%14 = load i8*, i8** %3
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %14)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%21 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %17, i32* %18, i32* %19, i32* %20)
store i32 %21, i32* %6
%22 = load i32, i32* @stdout
%23 = load i32, i32* %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %47
27: ; preds = %2
%28 = load i32, i32* @stdout
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %30
30: ; preds = %41, %27
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32, i32* @stdout
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %34
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %30
44: ; preds = %30
%45 = load i32, i32* @stdout
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %44, %2
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [28 x i8] c"\0Aread %d characters = \22%s\22\0A\00"
@.str.1 = [13 x i8] c"%x %x %x %x\0A\00"
@.str.2 = [38 x i8] c"...converted %d exadecimal integer(s)\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [4 x i8] c"%x \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @process_buffer(i8* %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %6
%7 = load i32, i32* @stdout
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %0)
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%13 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12)
%14 = load i32, i32* @stdout
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%16 = icmp sgt i32 %13, 0
br i1 %16, label %17, label %32
17: ; preds = %2
%18 = load i32, i32* @stdout
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = zext i32 %13 to i64
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %27, %21 ]
%23 = load i32, i32* @stdout
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %22
%25 = load i32, i32* %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %20
br i1 %28, label %29, label %21
29: ; preds = %21
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %29, %2
ret void
}