#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ log_msg(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
void log_args(FILE *f, int argc, char *argv[]) {
  int i;
  char buf[(10 * 128)];
  for (i = 0; i < argc; i++) {
    sprintf(buf, "argv nr %d = %s \n", i, argv[i]);
    log_msg(f, buf);
  }
}


x86 assembly (clang, -O0):
<log_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1189 <log_args+0x69>
lea    -0x520(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe9a(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x520(%rbp),%rsi
call   1030 <log_msg@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <log_args+0x1d>
add    $0x520,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x508,%rsp
test   %esi,%esi
jle    1175 <log_args+0x55>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0xeba(%rip),%r12
mov    %rsp,%r13
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rcx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <log_msg@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <log_args+0x30>
add    $0x508,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"argv nr %d = %s \0A\00"
define void @log_args(i32* %0, i32 %1, i8** nocapture %2) {
%4 = alloca [1280 x i8]
%5 = getelementptr inbounds [1280 x i8], [1280 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %16, %9 ]
%11 = getelementptr inbounds i8*, i8** %2, i64 %10
%12 = load i8*, i8** %11
%13 = trunc i64 %10 to i32
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %12)
%15 = call i32 @log_msg(i32* %0, i8* %5)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %3
ret void
}