#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 *, int);
void test1(int argc, char **argv) {
  int x, i, j;
  unsigned char *ptr;
  printf("test1: argc %d\n", argc);
  x = argc;
  j = 0;
  ptr = (unsigned char *)&x;
  for (i = 0; i < 4; i++) {
    j += *ptr++;
  }
  printf("j %d\n", j);
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%esi
lea    0xed7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    117a <test1+0x6a>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <test1+0x3a>
mov    -0x1c(%rbp),%esi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rbx
mov    %edi,%ebx
lea    0xee6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%ecx
shr    $0x10,%ecx
mov    %ebx,%eax
shr    $0x18,%eax
movzbl %bl,%edx
movzbl %bh,%edi
add    %edx,%edi
movzbl %cl,%esi
add    %edi,%esi
add    %eax,%esi
lea    0xecf(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"test1: argc %d\0A\00"
@.str.1 = [6 x i8] c"j %d\0A\00"
define void @test1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
store i32 %11, i32* %5
store i32 0, i32* %7
%12 = bitcast i32* %5 to i8*
store i8* %12, i8** %8
store i32 0, i32* %6
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %8
%19 = load i8, i8* %17
%20 = zext i8 %19 to i32
%21 = load i32, i32* %7
%22 = add nsw i32 %21, %20
store i32 %22, i32* %7
br label %23
23: ; preds = %16
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %13
26: ; preds = %13
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %27)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"test1: argc %d\0A\00"
@.str.1 = [6 x i8] c"j %d\0A\00"
define void @test1(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = lshr i32 %0, 8
%5 = lshr i32 %0, 16
%6 = lshr i32 %0, 24
%7 = and i32 %0, 255
%8 = and i32 %4, 255
%9 = add nuw nsw i32 %7, %8
%10 = and i32 %5, 255
%11 = add nuw nsw i32 %9, %10
%12 = add nuw nsw i32 %11, %6
%13 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret void
}