#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 authdaemondo(char *, int (*)(struct authinfo *, void *), void *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
int auth_daemon_pre(const char *uid, const char *service,
                    int (*callback)(struct authinfo *, void *), void *arg) {
  char *buf = malloc(strlen(service) + strlen(uid) + 20);
  int rc;
  if (!buf) {
    perror("malloc");
    return (1);
  }
  strcat(strcat(strcat(strcat(strcpy(buf, "PRE . "), service), " "), uid),
         "\n");
  rc = authdaemondo(buf, callback, arg);
  free(buf);
  return (rc);
}


x86 assembly (clang, -O0):
<auth_daemon_pre>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x14,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d5 <auth_daemon_pre+0x65>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <auth_daemon_pre+0xca>
mov    -0x30(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1040 <strcpy@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    %eax,%edi
lea    0xe13(%rip),%rsi
call   1090 <strcat@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    %eax,%edi
lea    0xdfc(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <authdaemondo@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auth_daemon_pre>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x14,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1217 <auth_daemon_pre+0xa7>
mov    %rax,%rbx
lea    0xe51(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %eax,%edi
mov    %r13,%rsi
call   1090 <strcat@plt>
lea    0xe3d(%rip),%rsi
mov    %eax,%edi
call   1090 <strcat@plt>
mov    %eax,%edi
mov    %r12,%rsi
call   1090 <strcat@plt>
lea    0xe27(%rip),%rsi
mov    %eax,%edi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <authdaemondo@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde2(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    1208 <auth_daemon_pre+0x98>

LLVM IR (-O0):
%struct.authinfo = type opaque
%struct.authinfo.0 = type opaque
@.str = [7 x i8] c"malloc\00"
@.str.1 = [7 x i8] c"PRE . \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @auth_daemon_pre(i8* %0, i8* %1, i32 (%struct.authinfo*, i8*)* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32 (%struct.authinfo*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 (%struct.authinfo*, i8*)* %2, i32 (%struct.authinfo*, i8*)** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %7
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = add nsw i64 %16, 20
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %4
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %40
23: ; preds = %4
%24 = load i8*, i8** %10
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8*, i8** %7
%27 = call i32 @strcat(i32 %25, i8* %26)
%28 = call i32 @strcat(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i32 %28, i8* %29)
%31 = call i32 @strcat(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = load i8*, i8** %10
%33 = load i32 (%struct.authinfo*, i8*)*, i32 (%struct.authinfo*, i8*)** %8
%34 = bitcast i32 (%struct.authinfo*, i8*)* %33 to i32 (%struct.authinfo.0*, i8*)*
%35 = load i8*, i8** %9
%36 = call i32 @authdaemondo(i8* %32, i32 (%struct.authinfo.0*, i8*)* %34, i8* %35)
store i32 %36, i32* %11
%37 = load i8*, i8** %10
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %11
store i32 %39, i32* %5
br label %40
40: ; preds = %23, %21
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
%struct.authinfo = type opaque
%struct.authinfo.0 = type opaque
@.str = [7 x i8] c"malloc\00"
@.str.1 = [7 x i8] c"PRE . \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @auth_daemon_pre(i8* %0, i8* %1, i32 (%struct.authinfo*, i8*)* %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add i64 %5, 20
%8 = add i64 %7, %6
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %22
13: ; preds = %4
%14 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @strcat(i32 %14, i8* %1)
%16 = tail call i32 @strcat(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @strcat(i32 %16, i8* %0)
%18 = tail call i32 @strcat(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = bitcast i32 (%struct.authinfo*, i8*)* %2 to i32 (%struct.authinfo.0*, i8*)*
%20 = tail call i32 @authdaemondo(i8* %9, i32 (%struct.authinfo.0*, i8*)* %19, i8* %3)
%21 = tail call i32 @free(i8* %9)
br label %22
22: ; preds = %13, %11
%23 = phi i32 [ %20, %13 ], [ 1, %11 ]
ret i32 %23
}